refactor: use LF line endings and use 4 spaces on all classes

This commit is contained in:
Chayapak Supasakul 2025-02-09 08:00:47 +07:00
parent 43527d9e6e
commit 50db974497
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
25 changed files with 2298 additions and 2255 deletions

View file

@ -21,7 +21,7 @@ public class CommandManager {
public static CommandManager INSTANCE; public static CommandManager INSTANCE;
public CommandManager (String prefix, CommandRegistryAccess commandRegistryAccess) { public CommandManager(String prefix, CommandRegistryAccess commandRegistryAccess) {
this.prefix = prefix; this.prefix = prefix;
TestCommand.register(this.dispatcher); TestCommand.register(this.dispatcher);
@ -40,7 +40,7 @@ public class CommandManager {
SelfCareCommand.register(this.dispatcher); SelfCareCommand.register(this.dispatcher);
} }
public void executeCommand (String command) { public void executeCommand(String command) {
final MinecraftClient client = MinecraftClient.getInstance(); final MinecraftClient client = MinecraftClient.getInstance();
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource(); final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
@ -56,7 +56,7 @@ public class CommandManager {
} }
} }
public Text getContext (CommandSyntaxException exception) { public Text getContext(CommandSyntaxException exception) {
final int _cursor = exception.getCursor(); final int _cursor = exception.getCursor();
final String input = exception.getInput(); final String input = exception.getInput();
@ -81,6 +81,11 @@ public class CommandManager {
return text; return text;
} }
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (String name) { return LiteralArgumentBuilder.literal(name); } public static LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument (String name, ArgumentType<T> type) { return RequiredArgumentBuilder.argument(name, type); } return LiteralArgumentBuilder.literal(name);
}
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument(String name, ArgumentType<T> type) {
return RequiredArgumentBuilder.argument(name, type);
}
} }

View file

@ -16,11 +16,13 @@ import land.chipmunk.chipmunkmod.util.TextUtilities;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import land.chipmunk.chipmunkmod.modules.CommandCore; import land.chipmunk.chipmunkmod.modules.CommandCore;
public class CoreCommand { public class CoreCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) { public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register( dispatcher.register(
literal("core") literal("core")
.then( .then(
@ -52,13 +54,13 @@ public class CoreCommand {
); );
} }
public static int run (CommandContext<FabricClientCommandSource> context) { public static int run(CommandContext<FabricClientCommandSource> context) {
CommandCore.INSTANCE.run(getString(context, "command")); CommandCore.INSTANCE.run(getString(context, "command"));
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public static int runTracked (CommandContext<FabricClientCommandSource> context) { public static int runTracked(CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource(); final FabricClientCommandSource source = context.getSource();
final String command = getString(context, "command"); final String command = getString(context, "command");
@ -78,13 +80,13 @@ public class CoreCommand {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public static int refill (CommandContext<FabricClientCommandSource> context) { public static int refill(CommandContext<FabricClientCommandSource> context) {
CommandCore.INSTANCE.refill(); CommandCore.INSTANCE.refill();
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public static int move (CommandContext<FabricClientCommandSource> context) { public static int move(CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource(); final FabricClientCommandSource source = context.getSource();
CommandCore.INSTANCE.move(source.getClient().player.getPos()); CommandCore.INSTANCE.move(source.getClient().player.getPos());
@ -99,7 +101,7 @@ public class CoreCommand {
CommandCore.INSTANCE.runFillCommand = bool; CommandCore.INSTANCE.runFillCommand = bool;
source.sendFeedback(Text.literal("Running fill commands are now " + (bool ? "enabled" : "disabled"))); source.sendFeedback(Text.literal("Running fill commands is now " + (bool ? "enabled" : "disabled")));
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }

View file

@ -4,12 +4,14 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static net.minecraft.command.argument.ItemStackArgumentType.itemStack; import static net.minecraft.command.argument.ItemStackArgumentType.itemStack;
import static net.minecraft.command.argument.ItemStackArgumentType.getItemStackArgument; import static net.minecraft.command.argument.ItemStackArgumentType.getItemStackArgument;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -18,7 +20,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public class ItemCommand { public class ItemCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) { public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
dispatcher.register( dispatcher.register(
literal("item") literal("item")
.then( .then(
@ -32,11 +34,11 @@ public class ItemCommand {
); );
} }
public static int setItem (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException { public static int setItem(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
return setItem(context, getInteger(context, "count")); return setItem(context, getInteger(context, "count"));
} }
public static int setItem (CommandContext<FabricClientCommandSource> context, int count) throws CommandSyntaxException { public static int setItem(CommandContext<FabricClientCommandSource> context, int count) throws CommandSyntaxException {
final FabricClientCommandSource source = context.getSource(); final FabricClientCommandSource source = context.getSource();
final MinecraftClient client = source.getClient(); final MinecraftClient client = source.getClient();

View file

@ -3,19 +3,21 @@ package land.chipmunk.chipmunkmod.commands;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
public class TestCommand { public class TestCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) { public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register( dispatcher.register(
literal("test") literal("test")
.executes(c -> helloWorld(c)) .executes(c -> helloWorld(c))
); );
} }
public static int helloWorld (CommandContext<FabricClientCommandSource> context) { public static int helloWorld(CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource(); final FabricClientCommandSource source = context.getSource();
source.sendFeedback(Text.literal("Hello, world!")); source.sendFeedback(Text.literal("Hello, world!"));

View file

@ -3,10 +3,12 @@ package land.chipmunk.chipmunkmod.commands;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal; import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument; import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen; import net.minecraft.client.gui.screen.TitleScreen;
@ -17,6 +19,7 @@ import net.minecraft.client.session.Session;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -26,7 +29,7 @@ public class UsernameCommand {
private static final Session ORIGINAL_SESSION = MinecraftClient.getInstance().getSession(); private static final Session ORIGINAL_SESSION = MinecraftClient.getInstance().getSession();
private static final SimpleCommandExceptionType USERNAME_TOO_LONG = new SimpleCommandExceptionType(Text.translatable("The specified username is longer than 16 characters")); private static final SimpleCommandExceptionType USERNAME_TOO_LONG = new SimpleCommandExceptionType(Text.translatable("The specified username is longer than 16 characters"));
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) { public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register( dispatcher.register(
literal("username") literal("username")
.then( .then(
@ -43,14 +46,14 @@ public class UsernameCommand {
); );
} }
public static int updateUsername (CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException { public static int updateUsername(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
final String username = getString(context, "username"); final String username = getString(context, "username");
if (username.length() > 16) throw USERNAME_TOO_LONG.create(); if (username.length() > 16) throw USERNAME_TOO_LONG.create();
final Session session = new Session(username, new UUID(0L, 0L), "", Optional.empty(), Optional.empty(), Session.AccountType.MOJANG); final Session session = new Session(username, new UUID(0L, 0L), "", Optional.empty(), Optional.empty(), Session.AccountType.MOJANG);
return updateSession(context, session); return updateSession(context, session);
} }
public static int updateSession (CommandContext<FabricClientCommandSource> context, Session session) throws CommandSyntaxException { public static int updateSession(CommandContext<FabricClientCommandSource> context, Session session) throws CommandSyntaxException {
final FabricClientCommandSource source = context.getSource(); final FabricClientCommandSource source = context.getSource();
final MinecraftClient client = source.getClient(); final MinecraftClient client = source.getClient();

View file

@ -11,7 +11,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*; import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*;
public class ValidateCommand { public class ValidateCommand {
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) { public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register( dispatcher.register(
literal("validate") literal("validate")
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command"))))) .then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))

View file

@ -44,8 +44,10 @@ public class Configuration {
public @Nullable String authKey; public @Nullable String authKey;
public @Nullable String formatKey; public @Nullable String formatKey;
public ChomeNSBotInfo() {} public ChomeNSBotInfo() {
public ChomeNSBotInfo (String prefix, @Nullable String key, @Nullable String authKey, @Nullable String formatKey) { }
public ChomeNSBotInfo(String prefix, @Nullable String key, @Nullable String authKey, @Nullable String formatKey) {
this.prefix = prefix; this.prefix = prefix;
this.key = key; this.key = key;
this.authKey = authKey; this.authKey = authKey;
@ -58,8 +60,10 @@ public class Configuration {
public String prefix; public String prefix;
public @Nullable String webhookUrl; public @Nullable String webhookUrl;
public TestBotInfo() {} public TestBotInfo() {
public TestBotInfo (String prefix, @Nullable String webhookUrl) { }
public TestBotInfo(String prefix, @Nullable String webhookUrl) {
this.prefix = prefix; this.prefix = prefix;
this.webhookUrl = webhookUrl; this.webhookUrl = webhookUrl;
} }
@ -70,8 +74,10 @@ public class Configuration {
public String prefix; public String prefix;
public @Nullable String key; public @Nullable String key;
public BotInfo() {} public BotInfo() {
public BotInfo (String prefix, @Nullable String key) { }
public BotInfo(String prefix, @Nullable String key) {
this.prefix = prefix; this.prefix = prefix;
this.key = key; this.key = key;
} }

View file

@ -47,7 +47,8 @@ public record ChomeNSBotCommand(String name, TrustLevel trustLevel, List<String>
try { try {
return TrustLevel.valueOf(trustLevelString); return TrustLevel.valueOf(trustLevelString);
} catch (final IllegalArgumentException ignored) {} } catch (final IllegalArgumentException ignored) {
}
return null; return null;
} }

View file

@ -31,10 +31,11 @@ public class ChatInputSuggestorMixin {
private CompletableFuture<Suggestions> pendingSuggestions; private CompletableFuture<Suggestions> pendingSuggestions;
@Shadow @Shadow
public void show (boolean narrateFirstSuggestion) {} public void show(boolean narrateFirstSuggestion) {
}
@Shadow @Shadow
private static int getStartOfCurrentWord (String input) { private static int getStartOfCurrentWord(String input) {
return 0; return 0;
} }
@ -43,12 +44,12 @@ public class ChatInputSuggestorMixin {
@Shadow @Shadow
final TextFieldWidget textField; final TextFieldWidget textField;
public ChatInputSuggestorMixin () { public ChatInputSuggestorMixin() {
textField = null; textField = null;
} }
@Inject(at = @At("TAIL"), method = "refresh()V") @Inject(at = @At("TAIL"), method = "refresh()V")
public void refresh (CallbackInfo ci) { public void refresh(CallbackInfo ci) {
final CommandManager commandManager = CommandManager.INSTANCE; final CommandManager commandManager = CommandManager.INSTANCE;
final String text = this.textField.getText(); final String text = this.textField.getText();

View file

@ -28,15 +28,20 @@ import java.util.List;
@Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class) @Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class)
public abstract class ChatScreenMixin extends Screen { public abstract class ChatScreenMixin extends Screen {
@Shadow private String originalChatText; @Shadow
private String originalChatText;
@Shadow private int messageHistoryIndex; @Shadow
private int messageHistoryIndex;
@Shadow protected TextFieldWidget chatField; @Shadow
protected TextFieldWidget chatField;
@Shadow ChatInputSuggestor chatInputSuggestor; @Shadow
ChatInputSuggestor chatInputSuggestor;
@Shadow protected abstract void onChatFieldUpdate(String chatText); @Shadow
protected abstract void onChatFieldUpdate(String chatText);
protected ChatScreenMixin(Text title) { protected ChatScreenMixin(Text title) {
super(title); super(title);
@ -44,7 +49,7 @@ public abstract class ChatScreenMixin extends Screen {
// infinite chat // infinite chat
@Inject(method = "init", at = @At("HEAD"), cancellable = true) @Inject(method = "init", at = @At("HEAD"), cancellable = true)
protected void init (CallbackInfo ci) { protected void init(CallbackInfo ci) {
final MinecraftClient client = MinecraftClient.getInstance(); final MinecraftClient client = MinecraftClient.getInstance();
this.messageHistoryIndex = client.inGameHud.getChatHud().getMessageHistory().size(); this.messageHistoryIndex = client.inGameHud.getChatHud().getMessageHistory().size();
@ -67,7 +72,7 @@ public abstract class ChatScreenMixin extends Screen {
} }
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true) @Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
private void sendMessage (String chatText, boolean addToHistory, CallbackInfo cir) { private void sendMessage(String chatText, boolean addToHistory, CallbackInfo cir) {
final MinecraftClient client = MinecraftClient.getInstance(); final MinecraftClient client = MinecraftClient.getInstance();
if (addToHistory) { if (addToHistory) {
@ -130,7 +135,8 @@ public abstract class ChatScreenMixin extends Screen {
cir.cancel(); cir.cancel();
return; return;
} catch (Exception ignored) {} } catch (Exception ignored) {
}
} }
} }

View file

@ -29,13 +29,13 @@ public class ClientConnectionMixin {
private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)"); private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)");
@Inject(method = "exceptionCaught", at = @At("HEAD"), cancellable = true) @Inject(method = "exceptionCaught", at = @At("HEAD"), cancellable = true)
private void exceptionCaught (ChannelHandlerContext context, Throwable ex, CallbackInfo ci) { private void exceptionCaught(ChannelHandlerContext context, Throwable ex, CallbackInfo ci) {
ci.cancel(); ci.cancel();
ex.printStackTrace(); ex.printStackTrace();
} }
@Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true) @Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true)
private static void handlePacket (Packet<?> packet, PacketListener _listener, CallbackInfo ci) { private static void handlePacket(Packet<?> packet, PacketListener _listener, CallbackInfo ci) {
for (Listener listener : ListenerManager.listeners) { for (Listener listener : ListenerManager.listeners) {
listener.packetReceived(packet); listener.packetReceived(packet);
} }
@ -81,7 +81,7 @@ public class ClientConnectionMixin {
} }
@Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;)V", cancellable = true) @Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;)V", cancellable = true)
private void sendPacket (Packet<?> packet, CallbackInfo ci) { private void sendPacket(Packet<?> packet, CallbackInfo ci) {
if (packet instanceof RequestCommandCompletionsC2SPacket t_packet) { if (packet instanceof RequestCommandCompletionsC2SPacket t_packet) {
if (t_packet.getPartialCommand().length() > 2048) { if (t_packet.getPartialCommand().length() > 2048) {
ci.cancel(); ci.cancel();

View file

@ -36,15 +36,20 @@ import java.time.Instant;
@Mixin(value = net.minecraft.client.network.ClientPlayNetworkHandler.class, priority = 1001) @Mixin(value = net.minecraft.client.network.ClientPlayNetworkHandler.class, priority = 1001)
public class ClientPlayNetworkHandlerMixin { public class ClientPlayNetworkHandlerMixin {
@Final @Final
@Shadow private FeatureSet enabledFeatures; @Shadow
private FeatureSet enabledFeatures;
@Final @Final
@Shadow private DynamicRegistryManager.Immutable combinedDynamicRegistries; @Shadow
@Shadow private LastSeenMessagesCollector lastSeenMessagesCollector; private DynamicRegistryManager.Immutable combinedDynamicRegistries;
@Shadow private MessageChain.Packer messagePacker; @Shadow
@Shadow private CommandDispatcher<CommandSource> commandDispatcher; private LastSeenMessagesCollector lastSeenMessagesCollector;
@Shadow
private MessageChain.Packer messagePacker;
@Shadow
private CommandDispatcher<CommandSource> commandDispatcher;
@Inject(method = "onGameJoin", at = @At("TAIL")) @Inject(method = "onGameJoin", at = @At("TAIL"))
private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) { private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures); final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries, this.enabledFeatures);
KaboomCheck.INSTANCE.onJoin(); KaboomCheck.INSTANCE.onJoin();
@ -64,7 +69,7 @@ public class ClientPlayNetworkHandlerMixin {
} }
@Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true) @Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true)
private void onGameMessage (GameMessageS2CPacket packet, CallbackInfo ci) { private void onGameMessage(GameMessageS2CPacket packet, CallbackInfo ci) {
final Text message = packet.content(); final Text message = packet.content();
try { try {
@ -80,7 +85,8 @@ public class ClientPlayNetworkHandlerMixin {
ci.cancel(); ci.cancel();
return; return;
} }
} catch (ClassCastException ignored) {} } catch (ClassCastException ignored) {
}
for (Listener listener : ListenerManager.listeners) { for (Listener listener : ListenerManager.listeners) {
listener.chatMessageReceived(message); listener.chatMessageReceived(message);
@ -93,12 +99,14 @@ public class ClientPlayNetworkHandlerMixin {
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID) || authId.equals(ChomeNSAuth.INSTANCE.id)) { if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID) || authId.equals(ChomeNSAuth.INSTANCE.id)) {
ci.cancel(); ci.cancel();
} }
} catch (Exception ignored) {} } catch (Exception ignored) {
} catch (Exception ignored) {} }
} catch (Exception ignored) {
}
} }
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void sendChatMessage (String chatText, CallbackInfo ci) { private void sendChatMessage(String chatText, CallbackInfo ci) {
final CommandManager commandManager = CommandManager.INSTANCE; final CommandManager commandManager = CommandManager.INSTANCE;
final String secret = String.valueOf(Chat.secret); final String secret = String.valueOf(Chat.secret);

View file

@ -10,5 +10,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
public interface MinecraftClientAccessor { public interface MinecraftClientAccessor {
@Mutable @Mutable
@Accessor("session") @Accessor("session")
void session (Session session); void session(Session session);
} }

View file

@ -43,16 +43,16 @@ public class CommandCore {
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance()); public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
public CommandCore (MinecraftClient client) { public CommandCore(MinecraftClient client) {
this.client = client; this.client = client;
reloadRelativeArea(); reloadRelativeArea();
} }
public void init () { public void init() {
if (timer != null) cleanup(); if (timer != null) cleanup();
final TimerTask task = new TimerTask() { final TimerTask task = new TimerTask() {
public void run () { public void run() {
tick(); tick();
} }
}; };
@ -84,7 +84,7 @@ public class CommandCore {
move(client.player.getPos()); move(client.player.getPos());
} }
private void tick () { private void tick() {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (networkHandler == null) { if (networkHandler == null) {
@ -96,11 +96,11 @@ public class CommandCore {
reloadRelativeArea(); reloadRelativeArea();
} }
public void reloadRelativeArea () { public void reloadRelativeArea() {
noPos = ChipmunkMod.CONFIG.core.relativeArea; noPos = ChipmunkMod.CONFIG.core.relativeArea;
} }
public void check () { public void check() {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (networkHandler == null || withPos == null || !ready) return; if (networkHandler == null || withPos == null || !ready) return;
@ -135,7 +135,7 @@ public class CommandCore {
} }
} }
public void move (Vec3d position) { public void move(Vec3d position) {
final ClientWorld world = client.world; final ClientWorld world = client.world;
if (world == null || noPos == null) return; if (world == null || noPos == null) return;
@ -168,7 +168,7 @@ public class CommandCore {
} }
} }
public void refill () { public void refill() {
if (!runFillCommand || withPos == null) return; if (!runFillCommand || withPos == null) return;
final String command = String.format( final String command = String.format(
@ -187,7 +187,7 @@ public class CommandCore {
client.getNetworkHandler().sendChatCommand(command); client.getNetworkHandler().sendChatCommand(command);
} }
public void incrementCurrentBlock () { public void incrementCurrentBlock() {
if (withPos == null) return; if (withPos == null) return;
int x = block.getX(); int x = block.getX();
int y = block.getY(); int y = block.getY();
@ -214,7 +214,7 @@ public class CommandCore {
block = new BlockPos(x, y, z); block = new BlockPos(x, y, z);
} }
public void run (String command) { public void run(String command) {
if (command.length() > 32767) return; if (command.length() > 32767) return;
final ClientConnection connection = client.getNetworkHandler().getConnection(); final ClientConnection connection = client.getNetworkHandler().getConnection();
@ -261,7 +261,7 @@ public class CommandCore {
incrementCurrentBlock(); incrementCurrentBlock();
} }
public CompletableFuture<NbtCompound> runTracked (String command) { public CompletableFuture<NbtCompound> runTracked(String command) {
final ClientConnection connection = client.getNetworkHandler().getConnection(); final ClientConnection connection = client.getNetworkHandler().getConnection();
if (block == null) return new CompletableFuture<>(); if (block == null) return new CompletableFuture<>();
@ -308,7 +308,7 @@ public class CommandCore {
final Timer timer = new Timer(); final Timer timer = new Timer();
final TimerTask queryTask = new TimerTask() { final TimerTask queryTask = new TimerTask() {
public void run () { public void run() {
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete); client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete);
timer.cancel(); // ? Is this necesary? timer.cancel(); // ? Is this necesary?
@ -321,7 +321,7 @@ public class CommandCore {
return future; return future;
} }
public void cleanup () { public void cleanup() {
if (timer == null) return; if (timer == null) return;
timer.cancel(); timer.cancel();

View file

@ -41,7 +41,7 @@ public class SelfCare implements Listener {
public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config? public static final SelfCare INSTANCE = new SelfCare(MinecraftClient.getInstance(), 70L, 500L); // make the intervals in config?
public SelfCare (MinecraftClient client, long interval, long chatInterval) { public SelfCare(MinecraftClient client, long interval, long chatInterval) {
this.client = client; this.client = client;
this.interval = interval; this.interval = interval;
this.chatInterval = chatInterval; this.chatInterval = chatInterval;
@ -51,17 +51,18 @@ public class SelfCare implements Listener {
ListenerManager.addListener(this); ListenerManager.addListener(this);
} }
public void init () {} public void init() {
}
public void onJoin () { public void onJoin() {
final TimerTask task = new TimerTask() { final TimerTask task = new TimerTask() {
public void run () { public void run() {
tick(); tick();
} }
}; };
final TimerTask chatTask = new TimerTask() { final TimerTask chatTask = new TimerTask() {
public void run () { public void run() {
chatTick(); chatTick();
} }
}; };
@ -73,7 +74,7 @@ public class SelfCare implements Listener {
chatTimer.schedule(chatTask, chatInterval, chatInterval); chatTimer.schedule(chatTask, chatInterval, chatInterval);
} }
public void cleanup () { public void cleanup() {
if (timer == null || chatTimer == null) return; if (timer == null || chatTimer == null) return;
timer.cancel(); timer.cancel();
@ -89,7 +90,7 @@ public class SelfCare implements Listener {
} }
@Override @Override
public void chatMessageReceived (Text message) { public void chatMessageReceived(Text message) {
final String stringMessage = message.getString(); final String stringMessage = message.getString();
if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true; if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true;
@ -102,7 +103,7 @@ public class SelfCare implements Listener {
) hasSkin = false; ) hasSkin = false;
} }
public void tick () { public void tick() {
final ClientPlayerEntity player = client.player; final ClientPlayerEntity player = client.player;
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
@ -111,16 +112,20 @@ public class SelfCare implements Listener {
return; return;
} }
if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); } if (player != null && !player.hasPermissionLevel(2) && opEnabled) {
else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative"); if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]");
} else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
else if (positionPacketsPerSecond >= 10 && icuEnabled) CommandCore.INSTANCE.run("sudo * icu stop"); else if (positionPacketsPerSecond >= 10 && icuEnabled) CommandCore.INSTANCE.run("sudo * icu stop");
} }
public void chatTick () { public void chatTick() {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); } if (!cspy && cspyEnabled) {
else if (!hasSkin && !skin.equals("off")) { if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin); } if (serverHasCommand("c")) networkHandler.sendChatCommand("c on");
} else if (!hasSkin && !skin.equals("off")) {
if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin);
}
} }
@Override @Override

View file

@ -23,26 +23,27 @@ public class Instrument {
public final int offset; public final int offset;
public final String sound; public final String sound;
private Instrument (int id, String name, int offset, String sound) { private Instrument(int id, String name, int offset, String sound) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.offset = offset; this.offset = offset;
this.sound = sound; this.sound = sound;
} }
private Instrument (int id, String name, int offset) { private Instrument(int id, String name, int offset) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.offset = offset; this.offset = offset;
this.sound = "minecraft:block.note_block." + name; this.sound = "minecraft:block.note_block." + name;
} }
public static Instrument of (String sound) { public static Instrument of(String sound) {
return new Instrument(-1, null, 0, sound); return new Instrument(-1, null, 0, sound);
} }
private static Instrument[] values = {HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING}; private static Instrument[] values = {HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING};
public static Instrument fromId (int id) {
public static Instrument fromId(int id) {
return values[id]; return values[id];
} }
} }

View file

@ -1,6 +1,7 @@
package land.chipmunk.chipmunkmod.song; package land.chipmunk.chipmunkmod.song;
import land.chipmunk.chipmunkmod.util.DownloadUtilities; import land.chipmunk.chipmunkmod.util.DownloadUtilities;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -69,11 +70,11 @@ public class MidiConverter {
while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) { while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) {
long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick; long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick;
prevTick = tempoEvents.get(tempoEventIdx).getTick(); prevTick = tempoEvents.get(tempoEventIdx).getTick();
microTime += (mpq/tpq) * deltaTick; microTime += (mpq / tpq) * deltaTick;
MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage(); MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage();
byte[] data = mm.getData(); byte[] data = mm.getData();
int new_mpq = (data[2]&0xFF) | ((data[1]&0xFF)<<8) | ((data[0]&0xFF)<<16); int new_mpq = (data[2] & 0xFF) | ((data[1] & 0xFF) << 8) | ((data[0] & 0xFF) << 16);
if (new_mpq != 0) mpq = new_mpq; if (new_mpq != 0) mpq = new_mpq;
tempoEventIdx++; tempoEventIdx++;
} }
@ -82,20 +83,18 @@ public class MidiConverter {
ShortMessage sm = (ShortMessage) message; ShortMessage sm = (ShortMessage) message;
if (sm.getCommand() == SET_INSTRUMENT) { if (sm.getCommand() == SET_INSTRUMENT) {
ids[sm.getChannel()] = sm.getData1(); ids[sm.getChannel()] = sm.getData1();
} } else if (sm.getCommand() == NOTE_ON) {
else if (sm.getCommand() == NOTE_ON) {
if (sm.getData2() == 0) continue; if (sm.getData2() == 0) continue;
int pitch = sm.getData1(); int pitch = sm.getData1();
int velocity = sm.getData2(); int velocity = sm.getData2();
long deltaTick = event.getTick() - prevTick; long deltaTick = event.getTick() - prevTick;
prevTick = event.getTick(); prevTick = event.getTick();
microTime += (mpq/tpq) * deltaTick; microTime += (mpq / tpq) * deltaTick;
Note note; Note note;
if (sm.getChannel() == 9) { if (sm.getChannel() == 9) {
note = getMidiPercussionNote(pitch, velocity, microTime); note = getMidiPercussionNote(pitch, velocity, microTime);
} } else {
else {
note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, velocity, microTime); note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, velocity, microTime);
} }
if (note != null) { if (note != null) {
@ -106,11 +105,10 @@ public class MidiConverter {
if (time > song.length) { if (time > song.length) {
song.length = time; song.length = time;
} }
} } else if (sm.getCommand() == NOTE_OFF) {
else if (sm.getCommand() == NOTE_OFF) {
long deltaTick = event.getTick() - prevTick; long deltaTick = event.getTick() - prevTick;
prevTick = event.getTick(); prevTick = event.getTick();
microTime += (mpq/tpq) * deltaTick; microTime += (mpq / tpq) * deltaTick;
long time = microTime / 1000L; long time = microTime / 1000L;
if (time > song.length) { if (time > song.length) {
song.length = time; song.length = time;
@ -130,7 +128,7 @@ public class MidiConverter {
Instrument[] instrumentList = instrumentMap.get(midiInstrument); Instrument[] instrumentList = instrumentMap.get(midiInstrument);
if (instrumentList != null) { if (instrumentList != null) {
for (Instrument candidateInstrument : instrumentList) { for (Instrument candidateInstrument : instrumentList) {
if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset+24) { if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset + 24) {
instrument = candidateInstrument; instrument = candidateInstrument;
break; break;
} }
@ -141,14 +139,14 @@ public class MidiConverter {
return null; return null;
} }
int pitch = midiPitch-instrument.offset; int pitch = midiPitch - instrument.offset;
float volume = (float) velocity / 127.0f; float volume = (float) velocity / 127.0f;
long time = microTime / 1000L; long time = microTime / 1000L;
return new Note(instrument, pitch, volume, time); return new Note(instrument, pitch, volume, time);
} }
private static Note getMidiPercussionNote (int midiPitch, int velocity, long microTime) { private static Note getMidiPercussionNote(int midiPitch, int velocity, long microTime) {
if (percussionMap.containsKey(midiPitch)) { if (percussionMap.containsKey(midiPitch)) {
int noteId = percussionMap.get(midiPitch); int noteId = percussionMap.get(midiPitch);
int pitch = noteId % 25; int pitch = noteId % 25;
@ -162,6 +160,7 @@ public class MidiConverter {
} }
public static HashMap<Integer, Instrument[]> instrumentMap = new HashMap<>(); public static HashMap<Integer, Instrument[]> instrumentMap = new HashMap<>();
static { static {
// Piano (HARP BASS BELL) // Piano (HARP BASS BELL)
instrumentMap.put(0, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Grand Piano instrumentMap.put(0, new Instrument[]{Instrument.HARP, Instrument.BASS, Instrument.BELL}); // Acoustic Grand Piano
@ -315,59 +314,60 @@ public class MidiConverter {
} }
public static HashMap<Integer, Integer> percussionMap = new HashMap<>(); public static HashMap<Integer, Integer> percussionMap = new HashMap<>();
static { static {
percussionMap.put(35, 10 + 25*Instrument.BASEDRUM.id); percussionMap.put(35, 10 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(36, 6 + 25*Instrument.BASEDRUM.id); percussionMap.put(36, 6 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(37, 6 + 25*Instrument.HAT.id); percussionMap.put(37, 6 + 25 * Instrument.HAT.id);
percussionMap.put(38, 8 + 25*Instrument.SNARE.id); percussionMap.put(38, 8 + 25 * Instrument.SNARE.id);
percussionMap.put(39, 6 + 25*Instrument.HAT.id); percussionMap.put(39, 6 + 25 * Instrument.HAT.id);
percussionMap.put(40, 4 + 25*Instrument.SNARE.id); percussionMap.put(40, 4 + 25 * Instrument.SNARE.id);
percussionMap.put(41, 6 + 25*Instrument.BASEDRUM.id); percussionMap.put(41, 6 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(42, 22 + 25*Instrument.SNARE.id); percussionMap.put(42, 22 + 25 * Instrument.SNARE.id);
percussionMap.put(43, 13 + 25*Instrument.BASEDRUM.id); percussionMap.put(43, 13 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(44, 22 + 25*Instrument.SNARE.id); percussionMap.put(44, 22 + 25 * Instrument.SNARE.id);
percussionMap.put(45, 15 + 25*Instrument.BASEDRUM.id); percussionMap.put(45, 15 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(46, 18 + 25*Instrument.SNARE.id); percussionMap.put(46, 18 + 25 * Instrument.SNARE.id);
percussionMap.put(47, 20 + 25*Instrument.BASEDRUM.id); percussionMap.put(47, 20 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(48, 23 + 25*Instrument.BASEDRUM.id); percussionMap.put(48, 23 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(49, 17 + 25*Instrument.SNARE.id); percussionMap.put(49, 17 + 25 * Instrument.SNARE.id);
percussionMap.put(50, 23 + 25*Instrument.BASEDRUM.id); percussionMap.put(50, 23 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(51, 24 + 25*Instrument.SNARE.id); percussionMap.put(51, 24 + 25 * Instrument.SNARE.id);
percussionMap.put(52, 8 + 25*Instrument.SNARE.id); percussionMap.put(52, 8 + 25 * Instrument.SNARE.id);
percussionMap.put(53, 13 + 25*Instrument.SNARE.id); percussionMap.put(53, 13 + 25 * Instrument.SNARE.id);
percussionMap.put(54, 18 + 25*Instrument.HAT.id); percussionMap.put(54, 18 + 25 * Instrument.HAT.id);
percussionMap.put(55, 18 + 25*Instrument.SNARE.id); percussionMap.put(55, 18 + 25 * Instrument.SNARE.id);
percussionMap.put(56, 1 + 25*Instrument.HAT.id); percussionMap.put(56, 1 + 25 * Instrument.HAT.id);
percussionMap.put(57, 13 + 25*Instrument.SNARE.id); percussionMap.put(57, 13 + 25 * Instrument.SNARE.id);
percussionMap.put(58, 2 + 25*Instrument.HAT.id); percussionMap.put(58, 2 + 25 * Instrument.HAT.id);
percussionMap.put(59, 13 + 25*Instrument.SNARE.id); percussionMap.put(59, 13 + 25 * Instrument.SNARE.id);
percussionMap.put(60, 9 + 25*Instrument.HAT.id); percussionMap.put(60, 9 + 25 * Instrument.HAT.id);
percussionMap.put(61, 2 + 25*Instrument.HAT.id); percussionMap.put(61, 2 + 25 * Instrument.HAT.id);
percussionMap.put(62, 8 + 25*Instrument.HAT.id); percussionMap.put(62, 8 + 25 * Instrument.HAT.id);
percussionMap.put(63, 22 + 25*Instrument.BASEDRUM.id); percussionMap.put(63, 22 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(64, 15 + 25*Instrument.BASEDRUM.id); percussionMap.put(64, 15 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(65, 13 + 25*Instrument.SNARE.id); percussionMap.put(65, 13 + 25 * Instrument.SNARE.id);
percussionMap.put(66, 8 + 25*Instrument.SNARE.id); percussionMap.put(66, 8 + 25 * Instrument.SNARE.id);
percussionMap.put(67, 8 + 25*Instrument.HAT.id); percussionMap.put(67, 8 + 25 * Instrument.HAT.id);
percussionMap.put(68, 3 + 25*Instrument.HAT.id); percussionMap.put(68, 3 + 25 * Instrument.HAT.id);
percussionMap.put(69, 20 + 25*Instrument.HAT.id); percussionMap.put(69, 20 + 25 * Instrument.HAT.id);
percussionMap.put(70, 23 + 25*Instrument.HAT.id); percussionMap.put(70, 23 + 25 * Instrument.HAT.id);
percussionMap.put(71, 24 + 25*Instrument.HAT.id); percussionMap.put(71, 24 + 25 * Instrument.HAT.id);
percussionMap.put(72, 24 + 25*Instrument.HAT.id); percussionMap.put(72, 24 + 25 * Instrument.HAT.id);
percussionMap.put(73, 17 + 25*Instrument.HAT.id); percussionMap.put(73, 17 + 25 * Instrument.HAT.id);
percussionMap.put(74, 11 + 25*Instrument.HAT.id); percussionMap.put(74, 11 + 25 * Instrument.HAT.id);
percussionMap.put(75, 18 + 25*Instrument.HAT.id); percussionMap.put(75, 18 + 25 * Instrument.HAT.id);
percussionMap.put(76, 9 + 25*Instrument.HAT.id); percussionMap.put(76, 9 + 25 * Instrument.HAT.id);
percussionMap.put(77, 5 + 25*Instrument.HAT.id); percussionMap.put(77, 5 + 25 * Instrument.HAT.id);
percussionMap.put(78, 22 + 25*Instrument.HAT.id); percussionMap.put(78, 22 + 25 * Instrument.HAT.id);
percussionMap.put(79, 19 + 25*Instrument.SNARE.id); percussionMap.put(79, 19 + 25 * Instrument.SNARE.id);
percussionMap.put(80, 17 + 25*Instrument.HAT.id); percussionMap.put(80, 17 + 25 * Instrument.HAT.id);
percussionMap.put(81, 22 + 25*Instrument.HAT.id); percussionMap.put(81, 22 + 25 * Instrument.HAT.id);
percussionMap.put(82, 22 + 25*Instrument.SNARE.id); percussionMap.put(82, 22 + 25 * Instrument.SNARE.id);
percussionMap.put(83, 24 + 25*Instrument.CHIME.id); percussionMap.put(83, 24 + 25 * Instrument.CHIME.id);
percussionMap.put(84, 24 + 25*Instrument.CHIME.id); percussionMap.put(84, 24 + 25 * Instrument.CHIME.id);
percussionMap.put(85, 21 + 25*Instrument.HAT.id); percussionMap.put(85, 21 + 25 * Instrument.HAT.id);
percussionMap.put(86, 14 + 25*Instrument.BASEDRUM.id); percussionMap.put(86, 14 + 25 * Instrument.BASEDRUM.id);
percussionMap.put(87, 7 + 25*Instrument.BASEDRUM.id); percussionMap.put(87, 7 + 25 * Instrument.BASEDRUM.id);
} }
} }

View file

@ -6,7 +6,7 @@ import java.nio.ByteOrder;
import java.util.ArrayList; import java.util.ArrayList;
public class NBSConverter { public class NBSConverter {
public static Instrument[] instrumentIndex = new Instrument[] { public static Instrument[] instrumentIndex = new Instrument[]{
Instrument.HARP, Instrument.HARP,
Instrument.BASS, Instrument.BASS,
Instrument.BASEDRUM, Instrument.BASEDRUM,
@ -121,7 +121,7 @@ public class NBSConverter {
ArrayList<NBSLayer> nbsLayers = new ArrayList<>(); ArrayList<NBSLayer> nbsLayers = new ArrayList<>();
if (buffer.hasRemaining()) { if (buffer.hasRemaining()) {
for (int i=0; i<layerCount; i++) { for (int i = 0; i < layerCount; i++) {
NBSLayer layer = new NBSLayer(); NBSLayer layer = new NBSLayer();
layer.name = getString(buffer, bytes.length); layer.name = getString(buffer, bytes.length);
if (format >= 4) { if (format >= 4) {
@ -172,16 +172,16 @@ public class NBSConverter {
layerVolume = nbsLayers.get(note.layer).volume; layerVolume = nbsLayers.get(note.layer).volume;
} }
int pitch = key-33; int pitch = key - 33;
song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo))); song.add(new Note(instrument, pitch, (float) note.velocity * (float) layerVolume / 10000f, getMilliTime(note.tick, tempo)));
} }
song.length = song.get(song.size()-1).time + 50; song.length = song.get(song.size() - 1).time + 50;
return song; return song;
} }
private static String getString (ByteBuffer buffer, int maxSize) throws IOException { private static String getString(ByteBuffer buffer, int maxSize) throws IOException {
int length = buffer.getInt(); int length = buffer.getInt();
if (length > maxSize) { if (length > maxSize) {
throw new IOException("String is too large"); throw new IOException("String is too large");

View file

@ -7,7 +7,7 @@ public class Note implements Comparable<Note> {
public float volume; public float volume;
public long time; public long time;
public Note (Instrument instrument, int pitch, float volume, long time) { public Note(Instrument instrument, int pitch, float volume, long time) {
this.instrument = instrument; this.instrument = instrument;
this.pitch = pitch; this.pitch = pitch;
this.volume = volume; this.volume = volume;
@ -18,16 +18,14 @@ public class Note implements Comparable<Note> {
public int compareTo(Note other) { public int compareTo(Note other) {
if (time < other.time) { if (time < other.time) {
return -1; return -1;
} } else if (time > other.time) {
else if (time > other.time) {
return 1; return 1;
} } else {
else {
return 0; return 0;
} }
} }
public int noteId () { public int noteId() {
return pitch + instrument.id * 25; return pitch + instrument.id * 25;
} }
} }

View file

@ -1,6 +1,7 @@
package land.chipmunk.chipmunkmod.song; package land.chipmunk.chipmunkmod.song;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -17,30 +18,30 @@ public class Song {
public int loopCount = 0; // Number of times to loop public int loopCount = 0; // Number of times to loop
public int currentLoop = 0; // Number of loops so far public int currentLoop = 0; // Number of loops so far
public Song (Component name) { public Song(Component name) {
this.name = name; this.name = name;
} }
public Song (String name) { public Song(String name) {
this(Component.text(name)); this(Component.text(name));
} }
public Note get (int i) { public Note get(int i) {
return notes.get(i); return notes.get(i);
} }
public void add (Note e) { public void add(Note e) {
notes.add(e); notes.add(e);
} }
public void sort () { public void sort() {
Collections.sort(notes); Collections.sort(notes);
} }
/** /**
* Starts playing song (does nothing if already playing) * Starts playing song (does nothing if already playing)
*/ */
public void play () { public void play() {
if (paused) { if (paused) {
paused = false; paused = false;
startTime = System.currentTimeMillis() - time; startTime = System.currentTimeMillis() - time;
@ -50,7 +51,7 @@ public class Song {
/** /**
* Pauses song (does nothing if already paused) * Pauses song (does nothing if already paused)
*/ */
public void pause () { public void pause() {
if (!paused) { if (!paused) {
paused = true; paused = true;
// Recalculates time so that the song will continue playing after the exact point it was paused // Recalculates time so that the song will continue playing after the exact point it was paused
@ -58,7 +59,7 @@ public class Song {
} }
} }
public void setTime (long t) { public void setTime(long t) {
time = t; time = t;
startTime = System.currentTimeMillis() - time; startTime = System.currentTimeMillis() - time;
position = 0; position = 0;
@ -67,11 +68,11 @@ public class Song {
} }
} }
public void advanceTime () { public void advanceTime() {
time = System.currentTimeMillis() - startTime; time = System.currentTimeMillis() - startTime;
} }
public boolean reachedNextNote () { public boolean reachedNextNote() {
if (position < notes.size()) { if (position < notes.size()) {
return notes.get(position).time <= time; return notes.get(position).time <= time;
} else { } else {
@ -88,7 +89,7 @@ public class Song {
} }
} }
public Note getNextNote () { public Note getNextNote() {
if (position >= notes.size()) { if (position >= notes.size()) {
if (shouldLoop()) { if (shouldLoop()) {
loop(); loop();
@ -99,11 +100,11 @@ public class Song {
return notes.get(position++); return notes.get(position++);
} }
public boolean finished () { public boolean finished() {
return time > length && !shouldLoop(); return time > length && !shouldLoop();
} }
private void loop () { private void loop() {
position = 0; position = 0;
startTime += length - loopPosition; startTime += length - loopPosition;
time -= length - loopPosition; time -= length - loopPosition;
@ -113,7 +114,7 @@ public class Song {
currentLoop++; currentLoop++;
} }
private boolean shouldLoop () { private boolean shouldLoop() {
if (looping) { if (looping) {
if (loopCount == 0) { if (loopCount == 0) {
return true; return true;
@ -125,7 +126,7 @@ public class Song {
} }
} }
public int size () { public int size() {
return notes.size(); return notes.size();
} }
} }

View file

@ -5,18 +5,18 @@ import net.minecraft.text.Text;
public class SongLoaderException extends Exception { public class SongLoaderException extends Exception {
public final Text message; public final Text message;
public SongLoaderException (Text message) { public SongLoaderException(Text message) {
super(); super();
this.message = message; this.message = message;
} }
public SongLoaderException (Text message, Throwable cause) { public SongLoaderException(Text message, Throwable cause) {
super(null, cause); super(null, cause);
this.message = message; this.message = message;
} }
@Override @Override
public String getMessage () { public String getMessage() {
return message.getString(); return message.getString();
} }
} }

View file

@ -19,17 +19,17 @@ public class SongLoaderThread extends Thread {
private boolean isUrl; private boolean isUrl;
public SongLoaderThread (URL location) throws SongLoaderException { public SongLoaderThread(URL location) throws SongLoaderException {
isUrl = true; isUrl = true;
songUrl = location; songUrl = location;
} }
public SongLoaderThread (Path location) throws SongLoaderException { public SongLoaderThread(Path location) throws SongLoaderException {
isUrl = false; isUrl = false;
songPath = location.toFile(); songPath = location.toFile();
} }
public void run () { public void run() {
byte[] bytes; byte[] bytes;
String name; String name;
try { try {
@ -62,7 +62,7 @@ public class SongLoaderThread extends Thread {
} }
} }
private File getSongFile (String name) { private File getSongFile(String name) {
return new File(SongPlayer.SONG_DIR, name); return new File(SongPlayer.SONG_DIR, name);
} }
} }

View file

@ -17,10 +17,12 @@ public class DownloadUtilities {
private static class DefaultTrustManager implements X509TrustManager { private static class DefaultTrustManager implements X509TrustManager {
@Override @Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) {} public void checkClientTrusted(X509Certificate[] arg0, String arg1) {
}
@Override @Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) {} public void checkServerTrusted(X509Certificate[] arg0, String arg1) {
}
@Override @Override
public X509Certificate[] getAcceptedIssuers() { public X509Certificate[] getAcceptedIssuers() {
@ -30,7 +32,7 @@ public class DownloadUtilities {
public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException { public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException {
SSLContext ctx = SSLContext.getInstance("TLS"); SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom()); ctx.init(new KeyManager[0], new TrustManager[]{new DefaultTrustManager()}, new SecureRandom());
SSLContext.setDefault(ctx); SSLContext.setDefault(ctx);
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
conn.setConnectTimeout(5000); conn.setConnectTimeout(5000);