Skip to content

Conversation

Jalvaviel
Copy link

Type of change

New Image element in HUD.

Description

You can select a new element to be rendered in your HUD: Image. It can load images from a filepath / URL and draw them in game. It also has support for GIFs.

Related issues

None

How Has This Been Tested?

image image

Checklist:

  • ✔ My code follows the style guidelines of this project.
  • ✔ I have added comments to my code in more complex areas.
  • ✔ I have tested the code in both development and production environments.

private static final Identifier LOADING_TEXTURE = Identifier.of(MOD_ID,"textures/icons/gui/loading_image.png");
private static final Color TRANSPARENT = new Color(255, 255, 255, 255);
private Identifier texture;
private final ExecutorService worker = Executors.newSingleThreadExecutor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be Util.getIoWorkerExecutor() or even virtual thread

private void composeImage(String path) {
// Cancel the future immediately to recreate another texture for the user.
if (currentImageDataFuture != null && !currentImageDataFuture.isDone()) {
currentImageDataFuture.cancel(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should debounce the modification rather than canceling?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you suggest a custom delay, or for the original image to finish loading?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, wait the original value stopped to change for 5 seconds, then we start to load.


currentImageDataFuture = CompletableFuture.supplyAsync(() -> {
try {
InputStream imageFile = path.startsWith("http") ? new URL(path).openStream() : new FileInputStream(parsed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might use Http?

}
} catch (Exception e) {
LOG.debug("Failed to load image", e);
texture = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it still accesses field texture on worker thread. Might move to exceptionallyAsync(..., mc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or volatile

public int canvasHeight;
public int framesPerColumn;
int totalFrames;
public List<Integer> delays;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be IntList

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the main difference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance, but it might not be important here.

@Jalvaviel
Copy link
Author

I updated this PR with the changes you wanted. Lmk if I need to tweak anything else. @MukjepScarlet

@Jalvaviel Jalvaviel marked this pull request as draft October 14, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants