tud please fork and reduce the size of the jar for the uh... spotify integration.

This commit is contained in:
Jess H 2024-06-07 04:28:13 +01:00
parent 5b37b06ee3
commit cfb1bbb05b
Signed by: UnixSystemV
GPG key ID: 9B21C50B68D67F19
5 changed files with 118 additions and 5 deletions

View file

@ -69,7 +69,8 @@ configurations {
dependencies {
minecraft('net.minecraftforge:forge:1.12.2-14.23.5.2860')
jarLibs('com.github.fzakaria:ascii85:1.2')
jarLibs('com.github.LabyStudio:java-spotify-api:+:all')
jarLibs('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
exclude module: 'launchwrapper'

View file

@ -62,6 +62,7 @@ public class Setup {
new Set(),
new Select(),
new Speed(),
new Spotify(),
new Test(),
new Timer(),
new TPAccept(),

View file

@ -281,6 +281,10 @@ public abstract class Feature extends ToggleButton implements SetCommand {
return true;
}
public boolean renderInHUD() {
return true;
}
public static class TriggerHandler {
}

View file

@ -0,0 +1,89 @@
package com.baseband.client.feature.client;
import com.baseband.client.BaseBand;
import com.baseband.client.feature.Feature;
import com.baseband.client.feature.Features;
import com.baseband.client.feature.category.ClientCategory;
import com.baseband.client.feature.render.HUD;
import com.baseband.client.registry.annotation.Config;
import de.labystudio.spotifyapi.SpotifyAPI;
import de.labystudio.spotifyapi.SpotifyAPIFactory;
import de.labystudio.spotifyapi.SpotifyListener;
import de.labystudio.spotifyapi.model.Track;
import java.text.SimpleDateFormat;
import java.util.Date;
@ClientCategory
public class Spotify extends Feature {
public SpotifyAPI api;
@Override
public String toString() {
return "Spotify";
}
@Config("RenderInHud")
public boolean renderInHUD;
@Override
public boolean renderInHUD() {
return renderInHUD;
}
@Override
public void onEveryTick() {
if(enabled != api.isConnected()) {
toggle();
}
Features.getFeature(HUD.class).spotifyLoaded = api.isConnected();
if (api.isConnected() && api.hasPosition() && api.hasTrack() && enabled && renderInHUD) {
text = this + "§7 [" + api.getTrack().getName() + " - " + api.getTrack().getArtist() + " (" + new SimpleDateFormat("mm:ss").format(new Date(api.getPosition())) + "/" + new SimpleDateFormat("mm:ss").format(new Date(api.getTrack().getLength())) + ")]";
} else {
text = toString();
}
}
@Override
public boolean canExist() {
api = SpotifyAPIFactory.create();
api.registerListener(new SpotifyListener() {
@Override
public void onConnect() {
BaseBand.LOGGER.info("Connected to Spotify");
}
@Override
public void onTrackChanged(Track track) {
}
@Override
public void onPositionChanged(int i) {
}
@Override
public void onPlayBackChanged(boolean b) {
}
@Override
public void onSync() {
}
@Override
public void onDisconnect(Exception e) {
BaseBand.LOGGER.info("Disconnected from Spotify");
e.printStackTrace();
}
});
api.initialize();
return true;
}
}

View file

@ -6,12 +6,14 @@ import com.baseband.client.feature.Feature;
import com.baseband.client.feature.Features;
import com.baseband.client.feature.category.Render;
import com.baseband.client.feature.client.Client;
import com.baseband.client.feature.client.Spotify;
import com.baseband.client.gui.GuiTheme;
import com.baseband.client.registry.annotation.*;
import com.baseband.client.util.adapt.Marker;
import com.baseband.client.util.interact.ServerDataManager;
import com.baseband.client.util.render.Pixels;
import com.baseband.client.util.render.TextSplitter;
import de.labystudio.spotifyapi.SpotifyAPI;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
@ -20,6 +22,7 @@ import net.minecraft.entity.Entity;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.baseband.client.BaseBand.LOGGER;
@ -98,15 +101,21 @@ public class HUD extends Feature {
@Gate(1)
public boolean showPing = true;
@Config("Show Spotify")
@Description("Shows the currently playing song of a locally running Spotify Instance.")
@Gate(1)
public boolean showSpotify = true;
@Config("Server Ping Jitter")
@Description("Makes your ping jitter up and down to make it seem more responsive.")
@Gate(1)
@Marker(3)
@Marker(2)
public boolean pingJitter = false;
@Config("Server Ping Jitter Amount")
@Description("See the above setting.")
@Gate(3)
@Gate(2)
@Range("0..10")
public int pingJitterAmount;
@ -191,7 +200,16 @@ public class HUD extends Feature {
if (showTPS && showPing)
infoString += " | ";
if (showPing)
infoString += "Ping: " + (ServerDataManager.ping + (pingJitter ? (int) (Math.random() * pingJitterAmount) : 0)) + " | Players: " + ServerDataManager.players + "/" + ServerDataManager.maxPlayers;
infoString += "Ping: " + (ServerDataManager.ping + (pingJitter ? (int) (Math.random() * pingJitterAmount) : 0)) + " | Players: " + ServerDataManager.players + "/" + ServerDataManager.maxPlayers + "\n";
if (showSpotify && spotifyLoaded) {
SpotifyAPI api = Features.getFeature(Spotify.class).api;
if (api != null && api.isConnected() && api.hasPosition() && api.hasTrack()) {
infoString += api.getTrack().getName() + " - " + api.getTrack().getArtist() + " (" + new SimpleDateFormat("mm:ss").format(new Date(api.getPosition())) + "/" + new SimpleDateFormat("mm:ss").format(new Date(api.getTrack().getLength())) + ")";
} else {
infoString += "Spotify not connected.";
}
}
if(infoString.endsWith("\n")) infoString = infoString.substring(0, infoString.length() - 1);
}
@ -201,7 +219,7 @@ public class HUD extends Feature {
}
int maxWidth = getStringWidth(initString);
Feature[] renderFeatures = Arrays.stream(features).filter(m -> m.enabled && m.category != Category.COMMAND && m.getClass() != Client.class && m != this).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(includeStatus ? value.text : value.toString()))).toArray(Feature[]::new);
Feature[] renderFeatures = Arrays.stream(features).filter(m -> m.enabled && m.category != Category.COMMAND && m.getClass() != Client.class && m != this && m.renderInHUD()).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(includeStatus ? value.text : value.toString()))).toArray(Feature[]::new);
for (Feature f : renderFeatures) {
maxWidth = Math.max(mc.fontRenderer.getStringWidth(f.text), maxWidth);
}