1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

Fix 3D icon inclusion in pack.zip, use right head animation identifier

This commit is contained in:
Eclipse
2025-10-19 17:48:58 +00:00
parent 8ccba795e7
commit a69c289947
5 changed files with 39 additions and 19 deletions

View File

@@ -68,11 +68,11 @@ public final class PackManager {
return currentPack.map(pack -> EXPORT_DIRECTORY.resolve(pack.name()));
}
public boolean finish() {
public boolean finish(Runnable onFinish) {
currentPack.map(pack -> {
RainbowIO.safeIO(() -> Files.writeString(getExportPath().orElseThrow().resolve(REPORT_FILE), createPackSummary(pack)));
return pack.save();
}).ifPresent(CompletableFuture::join);
}).ifPresent(future -> future.thenRun(onFinish));
boolean wasPresent = currentPack.isPresent();
currentPack = Optional.empty();
return wasPresent;

View File

@@ -113,11 +113,9 @@ public class PackGeneratorCommand {
.then(ClientCommandManager.literal("finish")
.executes(context -> {
Optional<Path> exportPath = packManager.getExportPath();
if (packManager.finish()) {
// TODO error when exporting fails
context.getSource().sendFeedback(Component.translatable("commands.rainbow.pack_finished_successfully")
.withStyle(style -> style.withUnderlined(true).withClickEvent(new ClickEvent.OpenFile(exportPath.orElseThrow()))));
} else {
Runnable onFinish = () -> context.getSource().sendFeedback(Component.translatable("commands.rainbow.pack_finished_successfully").withStyle(style
-> style.withUnderlined(true).withClickEvent(new ClickEvent.OpenFile(exportPath.orElseThrow()))));
if (!packManager.finish(onFinish)) {
context.getSource().sendError(NO_PACK_CREATED);
}
return 0;

View File

@@ -28,6 +28,9 @@ import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class RenderedTextureHolder extends TextureHolder {
private final ItemStack stackToRender;
@@ -53,18 +56,31 @@ public class RenderedTextureHolder extends TextureHolder {
Objects.requireNonNull(sizeBounds);
OversizedItemRenderState oversizedRenderState = new OversizedItemRenderState(guiItemRenderState, sizeBounds.left(), sizeBounds.top(), sizeBounds.right() + 4, sizeBounds.bottom() + 4);
Lock lock = new ReentrantLock();
Condition condition = lock.newCondition();
try (OversizedItemRenderer itemRenderer = new OversizedItemRenderer(Minecraft.getInstance().renderBuffers().bufferSource())) {
//noinspection DataFlowIssue
((PictureInPictureCopyRenderer) itemRenderer).rainbow$allowTextureCopy();
itemRenderer.prepare(oversizedRenderState, new GuiRenderState(), 4);
writeAsPNG(serializer, path, ((PictureInPictureRendererAccessor) itemRenderer).getTexture());
writeAsPNG(serializer, path, ((PictureInPictureRendererAccessor) itemRenderer).getTexture(), lock, condition);
}
return CompletableFuture.completedFuture(null);
return CompletableFuture.runAsync(() -> {
lock.lock();
try {
condition.await();
} catch (InterruptedException ignored) {
} finally {
lock.unlock();
}
});
}
// Simplified TextureUtil#writeAsPNG with some modifications to flip the image and just generate it at full size
private static void writeAsPNG(PackSerializer serializer, Path path, GpuTexture texture) {
private static void writeAsPNG(PackSerializer serializer, Path path, GpuTexture texture, Lock lock, Condition condition) {
RenderSystem.assertOnRenderThread();
int width = texture.getWidth(0);
int height = texture.getHeight(0);
int bufferSize = texture.getFormat().pixelSize() * width * height;
@@ -83,12 +99,18 @@ public class RenderedTextureHolder extends TextureHolder {
}
}
serializer.saveTexture(NativeImageUtil.writeToByteArray(image), path);
serializer.saveTexture(NativeImageUtil.writeToByteArray(image), path).join();
lock.lock();
try {
condition.signalAll();
} finally {
lock.unlock();
}
}
});
} finally {
buffer.close();
}
buffer.close();
};
commandEncoder.copyTextureToBuffer(texture, buffer, 0, writer, 0);
}