Jump to content

Recommended Posts

Posted

I am trying to create a HUD "Now Playing" element that displays the current song, artist, album, and corresponding album art live based on what the user is listening to using the Spotify API. Sort of like a widget, for now, that appears on the top left corner of the user's screen. Here's a visual representation of where I am currently (see top left).

In that square-like space to the left of the song details, I want to squeeze in the Album Art. I have an object that holds the image URL of the currently playing album, so I figured I would attempt something like this:

	private static String nowPlayingAlbum = spoticraftInstance.nowPlaying.item.album.images.get(1).url;
	
	private static ResourceLocation COVER_ART = new ResourceLocation(SpoticraftMod.MODID, nowPlayingAlbum == null ? "" : nowPlayingAlbum);

FYI, spoticraftInstance is a direct Gson mapping of the JSON response from Spotify's Get Currently Playing Track API. This updates every second on a separate thread so spoticraftInstance always contains the latest song information.

However upon launching the game it crashes with the following message:

Caused by: net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location: spoticraft:https://i.scdn.co/image/ab67616d00001e028dc0d801766a5aa6a33cbe37

This was a surprise, so I am trying to think of how to get around this properly. Should I download the image first, display it, then delete it after that song is no longer playing? Or is there a better way I am unaware of that will allow me to draw the image live as the URL changes? Here is the entire declaration of my HUD element for reference as of now:

import static com.example.spoticraft.SpoticraftCommon.literalOrEllipse;
import static com.example.spoticraft.SpoticraftMod.spoticraftInstance;

public class SpoticraftDrawing {
	private static String nowPlayingAlbum = spoticraftInstance.nowPlaying.item.album.images.get(1).url;
	
	private static ResourceLocation COVER_ART = new ResourceLocation(SpoticraftMod.MODID, nowPlayingAlbum == null ? "" : nowPlayingAlbum);
	private static final ResourceLocation BACKGROUND = new ResourceLocation(SpoticraftMod.MODID, "textures/background.png");
	
	public static final IGuiOverlay SPOTIFCRAFT_OVERLAY = ((gui, poseStack, partialTick, width, height) -> {
		int x = 5;
		int y = 5;
		int backgroundWidth = 200;
		int backgroundHeight = 50;
		
		RenderSystem.setShader(GameRenderer::getPositionTexShader);
		RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
		RenderSystem.setShaderTexture(0, BACKGROUND);
		NowPlaying currentSong = spoticraftInstance.nowPlaying;
		Font font = gui.getFont();
		
		GuiComponent.blit(poseStack, x, y, 0, 0, backgroundWidth, backgroundHeight, 0, 0);
		
		int textX = 50;
		
		if (currentSong != null) {
			RenderSystem.setShaderTexture(0, COVER_ART);
			GuiComponent.blit(poseStack, x + 5, 5, 0, 0, 50, 50, 0, 0);
			GuiComponent.drawString(poseStack, font, literalOrEllipse("§f§l" + currentSong.item.name), textX, 12, 0);
			GuiComponent.drawString(poseStack, font, literalOrEllipse("§e" + currentSong.item.artists.get(0).name), textX, 25, 0);
			GuiComponent.drawString(poseStack, font, literalOrEllipse("§6§o" + currentSong.item.album.name), textX, 38, 0);
		} else {
			if (SpoticraftMod.spoticraftInstance.getRefreshToken() == null) {
				GuiComponent.drawString(poseStack, font, "§f/spoticraft init to see your music", 20, 12, 0);				
			} else {
				GuiComponent.drawString(poseStack, font, "§6§oNothing Playing", 20, 12, 0);
			}
		}
	});
}

Thank you!

Posted

As it says, that is not a valid ResourceLocation. A ResourceLocation is not a URL.

For textures it represents a binding in the TextureManager that is typically populated during resource pack loading.

If you want something more dynamic try looking at what the SkinManager does, it downloads player skins from Mojang's website.

You can also use search where you will find variations of your question asked many times (along with many misunderstandings like yours).

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

Ok, so I have successfully created a Java class that saves the latest user's Spotify Session's album to a file named album_art.png. Here is where I am at so far:

public class SpoticraftArtDownloader {
	public static String imageURL = null;
	
	private static void downloadImage() throws Exception {
		if (imageURL == null) return;
		URL url = new URL(imageURL);
		InputStream in = new BufferedInputStream(url.openStream());
		OutputStream out = new BufferedOutputStream(new FileOutputStream("./album_art.png"));

		for ( int i; (i = in.read()) != -1; ) {
		    out.write(i);
		}
		in.close();
		out.close();
	}
	
	private static void deleteImage() {
		File file = new File("./album_art.png");
		if (file.exists()) file.delete();
	}
	
	public static void rotateImage(String url) throws Exception {
		deleteImage();
		imageURL = url;
		downloadImage();
	}
}

However, this is saving the image into the run directory, which from my understanding is inaccessible from the mod, with something like

ResourceLocation nowPlayingArt = new ResourceLocation(SpoticraftMod.MODID, "textures/album_art.png");
RenderSystem.setShaderTexture(0, nowPlayingArt);

How can I point SpoticraftArtDownloader to download the images into the textures folder?

Posted
On 4/20/2023 at 10:56 AM, warjort said:

... A ResourceLocation is not a URL.

For textures it represents a binding in the TextureManager ...

... try looking at what the SkinManager does,

 

i.e. its use of skinsDirectory and TextureManager.register()

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Try other builds of this modpack or report it to the modpack creator Looks like an issue with environmental, naturalist and/or crafttweaker
    • Hello! There is an issue with my world(Chocolate Edition modpack), after joining the world all creatures are frozen and the game is not responding or the game crashes after short period of time. Reproduction Steps: Turn on the game Join the world Game crashes immediately or after short period of time. Additional info: Crash log saying that an entity crashed the game is created after the crash(not the logs that I posted, different file from crash-logs, game crashed 3x by Snail, 1x by Small Snail, 1x by Tortoise) Specification: CPU: i5-13600KF GPU: GTX 1070 RAM: 32GB 3200MhZ - allocated 10GB Log links: latest.log: https://mclo.gs/Lp8zlsv crash-reports/crash: https://mclo.gs/XhtyJQI Minecraft version: 1.19.2 Modpack Version: Chocolate Edition 1.9 OS: Windows 10 Java Version: 22.0.2 Minecraft Java: Java 17
    • Hello, for several days I've been trying to find a way to add my animations in this style. @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { }   My current public class is : public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<EntityRenderState>   But i can't do that :  public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<T> Type parameter 'T' is not within its bound; should extend 'net.minecraft.client.renderer.entity.state.EntityRenderState' But with EntityRenderState it ok and it work !   But my setupAnim look like this :  @Override public void setupAnim(EntityRenderState p_370046_) { super.setupAnim(p_370046_); }   I don't have any access to my entity ! Look like 1.21.1 : @Override public void setupAnim(FakePlayerEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch); this.animateWalk(FakePlayerEntityAnimations.ANIM_PLAYERS_WALKING, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(entity.idleAnimationState, FakePlayerEntityAnimations.ANIM_PLAYERS_IDLE, ageInTicks, 1f); } But i'm stuck with new version of Forge...
    • Looks like an issue with abyssalsovereigns - this mod has functions that are not working on a server (client-side-only mod)
    • I added some new mods and updated old ones to my forge server and they will run successfully but the moment I try to join ill briefly load into the world and get booted with the message, internal server error. The mods in question work fine on singleplayer and removing too many from the server causes it to stop working so I cant be sure which one is causing the problem... any ideas? server log: https://pastebin.com/hGH8UUjm client log (from modrinth app): https://mclo.gs/a3oOUGY
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.