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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,6 @@ public class AnimationMapper {
|
||||
.withAnimation(identifier + ".head", BedrockAnimation.animation()
|
||||
.withLoopMode(BedrockAnimation.LoopMode.LOOP)
|
||||
.withBone(bone, headPosition, headRotation, headScale))
|
||||
.build(), "animation." + identifier + ".hold_first_person", "animation." + identifier + ".hold_third_person", identifier + ".head");
|
||||
.build(), "animation." + identifier + ".hold_first_person", "animation." + identifier + ".hold_third_person", "animation." + identifier + ".head");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,17 +134,17 @@ public class BedrockPack {
|
||||
futures.add(item.save(serializer, paths.attachables(), paths.geometry(), paths.animation(), textureSaver));
|
||||
}
|
||||
|
||||
if (paths.zipOutput().isPresent()) {
|
||||
RainbowIO.safeIO(() -> CodecUtil.tryZipDirectory(paths.packRoot(), paths.zipOutput().get()));
|
||||
}
|
||||
|
||||
if (reporter instanceof AutoCloseable closeable) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
|
||||
CompletableFuture<?> packSerializingFinished = CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
|
||||
if (paths.zipOutput().isPresent()) {
|
||||
return packSerializingFinished.thenAcceptAsync(object -> RainbowIO.safeIO(() -> CodecUtil.tryZipDirectory(paths.packRoot(), paths.zipOutput().get())));
|
||||
}
|
||||
return packSerializingFinished;
|
||||
}
|
||||
|
||||
public int getMappings() {
|
||||
|
||||
Reference in New Issue
Block a user