mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
refactor: use LF line endings and use 4 spaces on all classes
This commit is contained in:
parent
43527d9e6e
commit
50db974497
25 changed files with 2298 additions and 2255 deletions
|
|
@ -21,7 +21,7 @@ public class CommandManager {
|
|||
|
||||
public static CommandManager INSTANCE;
|
||||
|
||||
public CommandManager (String prefix, CommandRegistryAccess commandRegistryAccess) {
|
||||
public CommandManager(String prefix, CommandRegistryAccess commandRegistryAccess) {
|
||||
this.prefix = prefix;
|
||||
|
||||
TestCommand.register(this.dispatcher);
|
||||
|
|
@ -40,7 +40,7 @@ public class CommandManager {
|
|||
SelfCareCommand.register(this.dispatcher);
|
||||
}
|
||||
|
||||
public void executeCommand (String command) {
|
||||
public void executeCommand(String command) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
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 String input = exception.getInput();
|
||||
|
||||
|
|
@ -81,6 +81,11 @@ public class CommandManager {
|
|||
return text;
|
||||
}
|
||||
|
||||
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (String name) { return LiteralArgumentBuilder.literal(name); }
|
||||
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument (String name, ArgumentType<T> type) { return RequiredArgumentBuilder.argument(name, type); }
|
||||
public static LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
|
||||
return LiteralArgumentBuilder.literal(name);
|
||||
}
|
||||
|
||||
public static <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument(String name, ArgumentType<T> type) {
|
||||
return RequiredArgumentBuilder.argument(name, type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ import land.chipmunk.chipmunkmod.util.TextUtilities;
|
|||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import land.chipmunk.chipmunkmod.modules.CommandCore;
|
||||
|
||||
public class CoreCommand {
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("core")
|
||||
.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"));
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int runTracked (CommandContext<FabricClientCommandSource> context) {
|
||||
public static int runTracked(CommandContext<FabricClientCommandSource> context) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
|
||||
final String command = getString(context, "command");
|
||||
|
|
@ -78,13 +80,13 @@ public class CoreCommand {
|
|||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int refill (CommandContext<FabricClientCommandSource> context) {
|
||||
public static int refill(CommandContext<FabricClientCommandSource> context) {
|
||||
CommandCore.INSTANCE.refill();
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int move (CommandContext<FabricClientCommandSource> context) {
|
||||
public static int move(CommandContext<FabricClientCommandSource> context) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
|
||||
CommandCore.INSTANCE.move(source.getClient().player.getPos());
|
||||
|
|
@ -99,7 +101,7 @@ public class CoreCommand {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ import com.mojang.brigadier.Command;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static net.minecraft.command.argument.ItemStackArgumentType.itemStack;
|
||||
import static net.minecraft.command.argument.ItemStackArgumentType.getItemStackArgument;
|
||||
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
|
@ -18,7 +20,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.text.Text;
|
||||
|
||||
public class ItemCommand {
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
|
||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
|
||||
dispatcher.register(
|
||||
literal("item")
|
||||
.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"));
|
||||
}
|
||||
|
||||
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 MinecraftClient client = source.getClient();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,21 @@ package land.chipmunk.chipmunkmod.commands;
|
|||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class TestCommand {
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("test")
|
||||
.executes(c -> helloWorld(c))
|
||||
);
|
||||
}
|
||||
|
||||
public static int helloWorld (CommandContext<FabricClientCommandSource> context) {
|
||||
public static int helloWorld(CommandContext<FabricClientCommandSource> context) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
source.sendFeedback(Text.literal("Hello, world!"));
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package land.chipmunk.chipmunkmod.commands;
|
|||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
|
|
@ -17,6 +19,7 @@ import net.minecraft.client.session.Session;
|
|||
import net.minecraft.text.Text;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ public class UsernameCommand {
|
|||
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"));
|
||||
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("username")
|
||||
.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");
|
||||
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);
|
||||
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 MinecraftClient client = source.getClient();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
|||
import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*;
|
||||
|
||||
public class ValidateCommand {
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("validate")
|
||||
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))
|
||||
|
|
|
|||
|
|
@ -44,8 +44,10 @@ public class Configuration {
|
|||
public @Nullable String authKey;
|
||||
public @Nullable String formatKey;
|
||||
|
||||
public ChomeNSBotInfo() {}
|
||||
public ChomeNSBotInfo (String prefix, @Nullable String key, @Nullable String authKey, @Nullable String formatKey) {
|
||||
public ChomeNSBotInfo() {
|
||||
}
|
||||
|
||||
public ChomeNSBotInfo(String prefix, @Nullable String key, @Nullable String authKey, @Nullable String formatKey) {
|
||||
this.prefix = prefix;
|
||||
this.key = key;
|
||||
this.authKey = authKey;
|
||||
|
|
@ -58,8 +60,10 @@ public class Configuration {
|
|||
public String prefix;
|
||||
public @Nullable String webhookUrl;
|
||||
|
||||
public TestBotInfo() {}
|
||||
public TestBotInfo (String prefix, @Nullable String webhookUrl) {
|
||||
public TestBotInfo() {
|
||||
}
|
||||
|
||||
public TestBotInfo(String prefix, @Nullable String webhookUrl) {
|
||||
this.prefix = prefix;
|
||||
this.webhookUrl = webhookUrl;
|
||||
}
|
||||
|
|
@ -70,8 +74,10 @@ public class Configuration {
|
|||
public String prefix;
|
||||
public @Nullable String key;
|
||||
|
||||
public BotInfo() {}
|
||||
public BotInfo (String prefix, @Nullable String key) {
|
||||
public BotInfo() {
|
||||
}
|
||||
|
||||
public BotInfo(String prefix, @Nullable String key) {
|
||||
this.prefix = prefix;
|
||||
this.key = key;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ public record ChomeNSBotCommand(String name, TrustLevel trustLevel, List<String>
|
|||
|
||||
try {
|
||||
return TrustLevel.valueOf(trustLevelString);
|
||||
} catch (final IllegalArgumentException ignored) {}
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,11 @@ public class ChatInputSuggestorMixin {
|
|||
private CompletableFuture<Suggestions> pendingSuggestions;
|
||||
|
||||
@Shadow
|
||||
public void show (boolean narrateFirstSuggestion) {}
|
||||
public void show(boolean narrateFirstSuggestion) {
|
||||
}
|
||||
|
||||
@Shadow
|
||||
private static int getStartOfCurrentWord (String input) {
|
||||
private static int getStartOfCurrentWord(String input) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -43,12 +44,12 @@ public class ChatInputSuggestorMixin {
|
|||
@Shadow
|
||||
final TextFieldWidget textField;
|
||||
|
||||
public ChatInputSuggestorMixin () {
|
||||
public ChatInputSuggestorMixin() {
|
||||
textField = null;
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "refresh()V")
|
||||
public void refresh (CallbackInfo ci) {
|
||||
public void refresh(CallbackInfo ci) {
|
||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||
|
||||
final String text = this.textField.getText();
|
||||
|
|
|
|||
|
|
@ -28,15 +28,20 @@ import java.util.List;
|
|||
|
||||
@Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class)
|
||||
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) {
|
||||
super(title);
|
||||
|
|
@ -44,7 +49,7 @@ public abstract class ChatScreenMixin extends Screen {
|
|||
|
||||
// infinite chat
|
||||
@Inject(method = "init", at = @At("HEAD"), cancellable = true)
|
||||
protected void init (CallbackInfo ci) {
|
||||
protected void init(CallbackInfo ci) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
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)
|
||||
private void sendMessage (String chatText, boolean addToHistory, CallbackInfo cir) {
|
||||
private void sendMessage(String chatText, boolean addToHistory, CallbackInfo cir) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
if (addToHistory) {
|
||||
|
|
@ -130,7 +135,8 @@ public abstract class ChatScreenMixin extends Screen {
|
|||
cir.cancel();
|
||||
|
||||
return;
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ public class ClientConnectionMixin {
|
|||
private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)");
|
||||
|
||||
@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();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@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) {
|
||||
listener.packetReceived(packet);
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ public class ClientConnectionMixin {
|
|||
}
|
||||
|
||||
@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 (t_packet.getPartialCommand().length() > 2048) {
|
||||
ci.cancel();
|
||||
|
|
|
|||
|
|
@ -36,15 +36,20 @@ import java.time.Instant;
|
|||
@Mixin(value = net.minecraft.client.network.ClientPlayNetworkHandler.class, priority = 1001)
|
||||
public class ClientPlayNetworkHandlerMixin {
|
||||
@Final
|
||||
@Shadow private FeatureSet enabledFeatures;
|
||||
@Shadow
|
||||
private FeatureSet enabledFeatures;
|
||||
@Final
|
||||
@Shadow private DynamicRegistryManager.Immutable combinedDynamicRegistries;
|
||||
@Shadow private LastSeenMessagesCollector lastSeenMessagesCollector;
|
||||
@Shadow private MessageChain.Packer messagePacker;
|
||||
@Shadow private CommandDispatcher<CommandSource> commandDispatcher;
|
||||
@Shadow
|
||||
private DynamicRegistryManager.Immutable combinedDynamicRegistries;
|
||||
@Shadow
|
||||
private LastSeenMessagesCollector lastSeenMessagesCollector;
|
||||
@Shadow
|
||||
private MessageChain.Packer messagePacker;
|
||||
@Shadow
|
||||
private CommandDispatcher<CommandSource> commandDispatcher;
|
||||
|
||||
@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);
|
||||
|
||||
KaboomCheck.INSTANCE.onJoin();
|
||||
|
|
@ -64,7 +69,7 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
}
|
||||
|
||||
@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();
|
||||
|
||||
try {
|
||||
|
|
@ -80,7 +85,8 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
} catch (ClassCastException ignored) {}
|
||||
} catch (ClassCastException ignored) {
|
||||
}
|
||||
|
||||
for (Listener listener : ListenerManager.listeners) {
|
||||
listener.chatMessageReceived(message);
|
||||
|
|
@ -93,12 +99,14 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID) || authId.equals(ChomeNSAuth.INSTANCE.id)) {
|
||||
ci.cancel();
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@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 String secret = String.valueOf(Chat.secret);
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
|||
public interface MinecraftClientAccessor {
|
||||
@Mutable
|
||||
@Accessor("session")
|
||||
void session (Session session);
|
||||
void session(Session session);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,16 +43,16 @@ public class CommandCore {
|
|||
|
||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
|
||||
|
||||
public CommandCore (MinecraftClient client) {
|
||||
public CommandCore(MinecraftClient client) {
|
||||
this.client = client;
|
||||
reloadRelativeArea();
|
||||
}
|
||||
|
||||
public void init () {
|
||||
public void init() {
|
||||
if (timer != null) cleanup();
|
||||
|
||||
final TimerTask task = new TimerTask() {
|
||||
public void run () {
|
||||
public void run() {
|
||||
tick();
|
||||
}
|
||||
};
|
||||
|
|
@ -84,7 +84,7 @@ public class CommandCore {
|
|||
move(client.player.getPos());
|
||||
}
|
||||
|
||||
private void tick () {
|
||||
private void tick() {
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (networkHandler == null) {
|
||||
|
|
@ -96,11 +96,11 @@ public class CommandCore {
|
|||
reloadRelativeArea();
|
||||
}
|
||||
|
||||
public void reloadRelativeArea () {
|
||||
public void reloadRelativeArea() {
|
||||
noPos = ChipmunkMod.CONFIG.core.relativeArea;
|
||||
}
|
||||
|
||||
public void check () {
|
||||
public void check() {
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
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;
|
||||
if (world == null || noPos == null) return;
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ public class CommandCore {
|
|||
}
|
||||
}
|
||||
|
||||
public void refill () {
|
||||
public void refill() {
|
||||
if (!runFillCommand || withPos == null) return;
|
||||
|
||||
final String command = String.format(
|
||||
|
|
@ -187,7 +187,7 @@ public class CommandCore {
|
|||
client.getNetworkHandler().sendChatCommand(command);
|
||||
}
|
||||
|
||||
public void incrementCurrentBlock () {
|
||||
public void incrementCurrentBlock() {
|
||||
if (withPos == null) return;
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
|
|
@ -214,7 +214,7 @@ public class CommandCore {
|
|||
block = new BlockPos(x, y, z);
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
public void run(String command) {
|
||||
if (command.length() > 32767) return;
|
||||
|
||||
final ClientConnection connection = client.getNetworkHandler().getConnection();
|
||||
|
|
@ -261,7 +261,7 @@ public class CommandCore {
|
|||
incrementCurrentBlock();
|
||||
}
|
||||
|
||||
public CompletableFuture<NbtCompound> runTracked (String command) {
|
||||
public CompletableFuture<NbtCompound> runTracked(String command) {
|
||||
final ClientConnection connection = client.getNetworkHandler().getConnection();
|
||||
|
||||
if (block == null) return new CompletableFuture<>();
|
||||
|
|
@ -308,7 +308,7 @@ public class CommandCore {
|
|||
final Timer timer = new Timer();
|
||||
|
||||
final TimerTask queryTask = new TimerTask() {
|
||||
public void run () {
|
||||
public void run() {
|
||||
client.getNetworkHandler().getDataQueryHandler().queryBlockNbt(block, future::complete);
|
||||
|
||||
timer.cancel(); // ? Is this necesary?
|
||||
|
|
@ -321,7 +321,7 @@ public class CommandCore {
|
|||
return future;
|
||||
}
|
||||
|
||||
public void cleanup () {
|
||||
public void cleanup() {
|
||||
if (timer == null) return;
|
||||
|
||||
timer.cancel();
|
||||
|
|
|
|||
|
|
@ -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 SelfCare (MinecraftClient client, long interval, long chatInterval) {
|
||||
public SelfCare(MinecraftClient client, long interval, long chatInterval) {
|
||||
this.client = client;
|
||||
this.interval = interval;
|
||||
this.chatInterval = chatInterval;
|
||||
|
|
@ -51,17 +51,18 @@ public class SelfCare implements Listener {
|
|||
ListenerManager.addListener(this);
|
||||
}
|
||||
|
||||
public void init () {}
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public void onJoin () {
|
||||
public void onJoin() {
|
||||
final TimerTask task = new TimerTask() {
|
||||
public void run () {
|
||||
public void run() {
|
||||
tick();
|
||||
}
|
||||
};
|
||||
|
||||
final TimerTask chatTask = new TimerTask() {
|
||||
public void run () {
|
||||
public void run() {
|
||||
chatTick();
|
||||
}
|
||||
};
|
||||
|
|
@ -73,7 +74,7 @@ public class SelfCare implements Listener {
|
|||
chatTimer.schedule(chatTask, chatInterval, chatInterval);
|
||||
}
|
||||
|
||||
public void cleanup () {
|
||||
public void cleanup() {
|
||||
if (timer == null || chatTimer == null) return;
|
||||
|
||||
timer.cancel();
|
||||
|
|
@ -89,7 +90,7 @@ public class SelfCare implements Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void chatMessageReceived (Text message) {
|
||||
public void chatMessageReceived(Text message) {
|
||||
final String stringMessage = message.getString();
|
||||
|
||||
if (stringMessage.equals("Successfully enabled CommandSpy")) cspy = true;
|
||||
|
|
@ -102,7 +103,7 @@ public class SelfCare implements Listener {
|
|||
) hasSkin = false;
|
||||
}
|
||||
|
||||
public void tick () {
|
||||
public void tick() {
|
||||
final ClientPlayerEntity player = client.player;
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
|
|
@ -111,16 +112,20 @@ public class SelfCare implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (player != null && !player.hasPermissionLevel(2) && opEnabled) { if (serverHasCommand("op")) networkHandler.sendChatCommand("op @s[type=player]"); }
|
||||
else if (gameMode != 1 && gamemodeEnabled) networkHandler.sendChatCommand("gamemode creative");
|
||||
if (player != null && !player.hasPermissionLevel(2) && opEnabled) {
|
||||
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");
|
||||
}
|
||||
|
||||
public void chatTick () {
|
||||
public void chatTick() {
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); }
|
||||
else if (!hasSkin && !skin.equals("off")) { if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin); }
|
||||
if (!cspy && cspyEnabled) {
|
||||
if (serverHasCommand("c")) networkHandler.sendChatCommand("c on");
|
||||
} else if (!hasSkin && !skin.equals("off")) {
|
||||
if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,26 +23,27 @@ public class Instrument {
|
|||
public final int offset;
|
||||
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.name = name;
|
||||
this.offset = offset;
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
private Instrument (int id, String name, int offset) {
|
||||
private Instrument(int id, String name, int offset) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.offset = offset;
|
||||
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);
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chipmunkmod.song;
|
||||
|
||||
import land.chipmunk.chipmunkmod.util.DownloadUtilities;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.file.Paths;
|
||||
|
|
@ -69,11 +70,11 @@ public class MidiConverter {
|
|||
while (tempoEventIdx < tempoEvents.size() && event.getTick() > tempoEvents.get(tempoEventIdx).getTick()) {
|
||||
long deltaTick = tempoEvents.get(tempoEventIdx).getTick() - prevTick;
|
||||
prevTick = tempoEvents.get(tempoEventIdx).getTick();
|
||||
microTime += (mpq/tpq) * deltaTick;
|
||||
microTime += (mpq / tpq) * deltaTick;
|
||||
|
||||
MetaMessage mm = (MetaMessage) tempoEvents.get(tempoEventIdx).getMessage();
|
||||
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;
|
||||
tempoEventIdx++;
|
||||
}
|
||||
|
|
@ -82,20 +83,18 @@ public class MidiConverter {
|
|||
ShortMessage sm = (ShortMessage) message;
|
||||
if (sm.getCommand() == SET_INSTRUMENT) {
|
||||
ids[sm.getChannel()] = sm.getData1();
|
||||
}
|
||||
else if (sm.getCommand() == NOTE_ON) {
|
||||
} else if (sm.getCommand() == NOTE_ON) {
|
||||
if (sm.getData2() == 0) continue;
|
||||
int pitch = sm.getData1();
|
||||
int velocity = sm.getData2();
|
||||
long deltaTick = event.getTick() - prevTick;
|
||||
prevTick = event.getTick();
|
||||
microTime += (mpq/tpq) * deltaTick;
|
||||
microTime += (mpq / tpq) * deltaTick;
|
||||
|
||||
Note note;
|
||||
if (sm.getChannel() == 9) {
|
||||
note = getMidiPercussionNote(pitch, velocity, microTime);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
note = getMidiInstrumentNote(ids[sm.getChannel()], pitch, velocity, microTime);
|
||||
}
|
||||
if (note != null) {
|
||||
|
|
@ -106,11 +105,10 @@ public class MidiConverter {
|
|||
if (time > song.length) {
|
||||
song.length = time;
|
||||
}
|
||||
}
|
||||
else if (sm.getCommand() == NOTE_OFF) {
|
||||
} else if (sm.getCommand() == NOTE_OFF) {
|
||||
long deltaTick = event.getTick() - prevTick;
|
||||
prevTick = event.getTick();
|
||||
microTime += (mpq/tpq) * deltaTick;
|
||||
microTime += (mpq / tpq) * deltaTick;
|
||||
long time = microTime / 1000L;
|
||||
if (time > song.length) {
|
||||
song.length = time;
|
||||
|
|
@ -130,7 +128,7 @@ public class MidiConverter {
|
|||
Instrument[] instrumentList = instrumentMap.get(midiInstrument);
|
||||
if (instrumentList != null) {
|
||||
for (Instrument candidateInstrument : instrumentList) {
|
||||
if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset+24) {
|
||||
if (midiPitch >= candidateInstrument.offset && midiPitch <= candidateInstrument.offset + 24) {
|
||||
instrument = candidateInstrument;
|
||||
break;
|
||||
}
|
||||
|
|
@ -141,14 +139,14 @@ public class MidiConverter {
|
|||
return null;
|
||||
}
|
||||
|
||||
int pitch = midiPitch-instrument.offset;
|
||||
int pitch = midiPitch - instrument.offset;
|
||||
float volume = (float) velocity / 127.0f;
|
||||
long time = microTime / 1000L;
|
||||
|
||||
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)) {
|
||||
int noteId = percussionMap.get(midiPitch);
|
||||
int pitch = noteId % 25;
|
||||
|
|
@ -162,6 +160,7 @@ public class MidiConverter {
|
|||
}
|
||||
|
||||
public static HashMap<Integer, Instrument[]> instrumentMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
// Piano (HARP BASS BELL)
|
||||
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<>();
|
||||
|
||||
static {
|
||||
percussionMap.put(35, 10 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(36, 6 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(37, 6 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(38, 8 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(39, 6 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(40, 4 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(41, 6 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(42, 22 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(43, 13 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(44, 22 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(45, 15 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(46, 18 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(47, 20 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(48, 23 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(49, 17 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(50, 23 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(51, 24 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(52, 8 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(53, 13 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(54, 18 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(55, 18 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(56, 1 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(57, 13 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(58, 2 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(59, 13 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(60, 9 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(61, 2 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(62, 8 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(63, 22 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(64, 15 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(65, 13 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(66, 8 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(67, 8 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(68, 3 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(69, 20 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(70, 23 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(71, 24 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(72, 24 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(73, 17 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(74, 11 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(75, 18 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(76, 9 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(77, 5 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(78, 22 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(79, 19 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(80, 17 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(81, 22 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(82, 22 + 25*Instrument.SNARE.id);
|
||||
percussionMap.put(83, 24 + 25*Instrument.CHIME.id);
|
||||
percussionMap.put(84, 24 + 25*Instrument.CHIME.id);
|
||||
percussionMap.put(85, 21 + 25*Instrument.HAT.id);
|
||||
percussionMap.put(86, 14 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(87, 7 + 25*Instrument.BASEDRUM.id);
|
||||
percussionMap.put(35, 10 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(36, 6 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(37, 6 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(38, 8 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(39, 6 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(40, 4 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(41, 6 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(42, 22 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(43, 13 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(44, 22 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(45, 15 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(46, 18 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(47, 20 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(48, 23 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(49, 17 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(50, 23 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(51, 24 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(52, 8 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(53, 13 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(54, 18 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(55, 18 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(56, 1 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(57, 13 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(58, 2 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(59, 13 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(60, 9 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(61, 2 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(62, 8 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(63, 22 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(64, 15 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(65, 13 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(66, 8 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(67, 8 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(68, 3 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(69, 20 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(70, 23 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(71, 24 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(72, 24 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(73, 17 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(74, 11 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(75, 18 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(76, 9 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(77, 5 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(78, 22 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(79, 19 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(80, 17 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(81, 22 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(82, 22 + 25 * Instrument.SNARE.id);
|
||||
percussionMap.put(83, 24 + 25 * Instrument.CHIME.id);
|
||||
percussionMap.put(84, 24 + 25 * Instrument.CHIME.id);
|
||||
percussionMap.put(85, 21 + 25 * Instrument.HAT.id);
|
||||
percussionMap.put(86, 14 + 25 * Instrument.BASEDRUM.id);
|
||||
percussionMap.put(87, 7 + 25 * Instrument.BASEDRUM.id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import java.nio.ByteOrder;
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class NBSConverter {
|
||||
public static Instrument[] instrumentIndex = new Instrument[] {
|
||||
public static Instrument[] instrumentIndex = new Instrument[]{
|
||||
Instrument.HARP,
|
||||
Instrument.BASS,
|
||||
Instrument.BASEDRUM,
|
||||
|
|
@ -121,7 +121,7 @@ public class NBSConverter {
|
|||
|
||||
ArrayList<NBSLayer> nbsLayers = new ArrayList<>();
|
||||
if (buffer.hasRemaining()) {
|
||||
for (int i=0; i<layerCount; i++) {
|
||||
for (int i = 0; i < layerCount; i++) {
|
||||
NBSLayer layer = new NBSLayer();
|
||||
layer.name = getString(buffer, bytes.length);
|
||||
if (format >= 4) {
|
||||
|
|
@ -172,16 +172,16 @@ public class NBSConverter {
|
|||
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.length = song.get(song.size()-1).time + 50;
|
||||
song.length = song.get(song.size() - 1).time + 50;
|
||||
|
||||
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();
|
||||
if (length > maxSize) {
|
||||
throw new IOException("String is too large");
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ public class Note implements Comparable<Note> {
|
|||
public float volume;
|
||||
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.pitch = pitch;
|
||||
this.volume = volume;
|
||||
|
|
@ -18,16 +18,14 @@ public class Note implements Comparable<Note> {
|
|||
public int compareTo(Note other) {
|
||||
if (time < other.time) {
|
||||
return -1;
|
||||
}
|
||||
else if (time > other.time) {
|
||||
} else if (time > other.time) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int noteId () {
|
||||
public int noteId() {
|
||||
return pitch + instrument.id * 25;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chipmunkmod.song;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
|
|
@ -17,30 +18,30 @@ public class Song {
|
|||
public int loopCount = 0; // Number of times to loop
|
||||
public int currentLoop = 0; // Number of loops so far
|
||||
|
||||
public Song (Component name) {
|
||||
public Song(Component name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Song (String name) {
|
||||
public Song(String name) {
|
||||
this(Component.text(name));
|
||||
}
|
||||
|
||||
public Note get (int i) {
|
||||
public Note get(int i) {
|
||||
return notes.get(i);
|
||||
}
|
||||
|
||||
public void add (Note e) {
|
||||
public void add(Note e) {
|
||||
notes.add(e);
|
||||
}
|
||||
|
||||
public void sort () {
|
||||
public void sort() {
|
||||
Collections.sort(notes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts playing song (does nothing if already playing)
|
||||
*/
|
||||
public void play () {
|
||||
public void play() {
|
||||
if (paused) {
|
||||
paused = false;
|
||||
startTime = System.currentTimeMillis() - time;
|
||||
|
|
@ -50,7 +51,7 @@ public class Song {
|
|||
/**
|
||||
* Pauses song (does nothing if already paused)
|
||||
*/
|
||||
public void pause () {
|
||||
public void pause() {
|
||||
if (!paused) {
|
||||
paused = true;
|
||||
// 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;
|
||||
startTime = System.currentTimeMillis() - time;
|
||||
position = 0;
|
||||
|
|
@ -67,11 +68,11 @@ public class Song {
|
|||
}
|
||||
}
|
||||
|
||||
public void advanceTime () {
|
||||
public void advanceTime() {
|
||||
time = System.currentTimeMillis() - startTime;
|
||||
}
|
||||
|
||||
public boolean reachedNextNote () {
|
||||
public boolean reachedNextNote() {
|
||||
if (position < notes.size()) {
|
||||
return notes.get(position).time <= time;
|
||||
} else {
|
||||
|
|
@ -88,7 +89,7 @@ public class Song {
|
|||
}
|
||||
}
|
||||
|
||||
public Note getNextNote () {
|
||||
public Note getNextNote() {
|
||||
if (position >= notes.size()) {
|
||||
if (shouldLoop()) {
|
||||
loop();
|
||||
|
|
@ -99,11 +100,11 @@ public class Song {
|
|||
return notes.get(position++);
|
||||
}
|
||||
|
||||
public boolean finished () {
|
||||
public boolean finished() {
|
||||
return time > length && !shouldLoop();
|
||||
}
|
||||
|
||||
private void loop () {
|
||||
private void loop() {
|
||||
position = 0;
|
||||
startTime += length - loopPosition;
|
||||
time -= length - loopPosition;
|
||||
|
|
@ -113,7 +114,7 @@ public class Song {
|
|||
currentLoop++;
|
||||
}
|
||||
|
||||
private boolean shouldLoop () {
|
||||
private boolean shouldLoop() {
|
||||
if (looping) {
|
||||
if (loopCount == 0) {
|
||||
return true;
|
||||
|
|
@ -125,7 +126,7 @@ public class Song {
|
|||
}
|
||||
}
|
||||
|
||||
public int size () {
|
||||
public int size() {
|
||||
return notes.size();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,18 +5,18 @@ import net.minecraft.text.Text;
|
|||
public class SongLoaderException extends Exception {
|
||||
public final Text message;
|
||||
|
||||
public SongLoaderException (Text message) {
|
||||
public SongLoaderException(Text message) {
|
||||
super();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SongLoaderException (Text message, Throwable cause) {
|
||||
public SongLoaderException(Text message, Throwable cause) {
|
||||
super(null, cause);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage () {
|
||||
public String getMessage() {
|
||||
return message.getString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,17 +19,17 @@ public class SongLoaderThread extends Thread {
|
|||
|
||||
private boolean isUrl;
|
||||
|
||||
public SongLoaderThread (URL location) throws SongLoaderException {
|
||||
public SongLoaderThread(URL location) throws SongLoaderException {
|
||||
isUrl = true;
|
||||
songUrl = location;
|
||||
}
|
||||
|
||||
public SongLoaderThread (Path location) throws SongLoaderException {
|
||||
public SongLoaderThread(Path location) throws SongLoaderException {
|
||||
isUrl = false;
|
||||
songPath = location.toFile();
|
||||
}
|
||||
|
||||
public void run () {
|
||||
public void run() {
|
||||
byte[] bytes;
|
||||
String name;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@ public class DownloadUtilities {
|
|||
private static class DefaultTrustManager implements X509TrustManager {
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] arg0, String arg1) {}
|
||||
public void checkClientTrusted(X509Certificate[] arg0, String arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] arg0, String arg1) {}
|
||||
public void checkServerTrusted(X509Certificate[] arg0, String arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
|
|
@ -30,7 +32,7 @@ public class DownloadUtilities {
|
|||
|
||||
public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException {
|
||||
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);
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setConnectTimeout(5000);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue