Skip to content

Commit a69c289

Browse files
Fix 3D icon inclusion in pack.zip, use right head animation identifier
1 parent 8ccba79 commit a69c289

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

client/src/main/java/org/geysermc/rainbow/client/PackManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public Optional<Path> getExportPath() {
6868
return currentPack.map(pack -> EXPORT_DIRECTORY.resolve(pack.name()));
6969
}
7070

71-
public boolean finish() {
71+
public boolean finish(Runnable onFinish) {
7272
currentPack.map(pack -> {
7373
RainbowIO.safeIO(() -> Files.writeString(getExportPath().orElseThrow().resolve(REPORT_FILE), createPackSummary(pack)));
7474
return pack.save();
75-
}).ifPresent(CompletableFuture::join);
75+
}).ifPresent(future -> future.thenRun(onFinish));
7676
boolean wasPresent = currentPack.isPresent();
7777
currentPack = Optional.empty();
7878
return wasPresent;

client/src/main/java/org/geysermc/rainbow/client/command/PackGeneratorCommand.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
113113
.then(ClientCommandManager.literal("finish")
114114
.executes(context -> {
115115
Optional<Path> exportPath = packManager.getExportPath();
116-
if (packManager.finish()) {
117-
// TODO error when exporting fails
118-
context.getSource().sendFeedback(Component.translatable("commands.rainbow.pack_finished_successfully")
119-
.withStyle(style -> style.withUnderlined(true).withClickEvent(new ClickEvent.OpenFile(exportPath.orElseThrow()))));
120-
} else {
116+
Runnable onFinish = () -> context.getSource().sendFeedback(Component.translatable("commands.rainbow.pack_finished_successfully").withStyle(style
117+
-> style.withUnderlined(true).withClickEvent(new ClickEvent.OpenFile(exportPath.orElseThrow()))));
118+
if (!packManager.finish(onFinish)) {
121119
context.getSource().sendError(NO_PACK_CREATED);
122120
}
123121
return 0;

client/src/main/java/org/geysermc/rainbow/client/render/RenderedTextureHolder.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import java.util.Objects;
2929
import java.util.Optional;
3030
import java.util.concurrent.CompletableFuture;
31+
import java.util.concurrent.locks.Condition;
32+
import java.util.concurrent.locks.Lock;
33+
import java.util.concurrent.locks.ReentrantLock;
3134

3235
public class RenderedTextureHolder extends TextureHolder {
3336
private final ItemStack stackToRender;
@@ -53,18 +56,31 @@ public CompletableFuture<?> save(AssetResolver assetResolver, PackSerializer ser
5356
Objects.requireNonNull(sizeBounds);
5457
OversizedItemRenderState oversizedRenderState = new OversizedItemRenderState(guiItemRenderState, sizeBounds.left(), sizeBounds.top(), sizeBounds.right() + 4, sizeBounds.bottom() + 4);
5558

59+
Lock lock = new ReentrantLock();
60+
Condition condition = lock.newCondition();
61+
5662
try (OversizedItemRenderer itemRenderer = new OversizedItemRenderer(Minecraft.getInstance().renderBuffers().bufferSource())) {
5763
//noinspection DataFlowIssue
5864
((PictureInPictureCopyRenderer) itemRenderer).rainbow$allowTextureCopy();
5965
itemRenderer.prepare(oversizedRenderState, new GuiRenderState(), 4);
60-
writeAsPNG(serializer, path, ((PictureInPictureRendererAccessor) itemRenderer).getTexture());
66+
writeAsPNG(serializer, path, ((PictureInPictureRendererAccessor) itemRenderer).getTexture(), lock, condition);
6167
}
62-
return CompletableFuture.completedFuture(null);
68+
69+
return CompletableFuture.runAsync(() -> {
70+
lock.lock();
71+
try {
72+
condition.await();
73+
} catch (InterruptedException ignored) {
74+
} finally {
75+
lock.unlock();
76+
}
77+
});
6378
}
6479

6580
// Simplified TextureUtil#writeAsPNG with some modifications to flip the image and just generate it at full size
66-
private static void writeAsPNG(PackSerializer serializer, Path path, GpuTexture texture) {
81+
private static void writeAsPNG(PackSerializer serializer, Path path, GpuTexture texture, Lock lock, Condition condition) {
6782
RenderSystem.assertOnRenderThread();
83+
6884
int width = texture.getWidth(0);
6985
int height = texture.getHeight(0);
7086
int bufferSize = texture.getFormat().pixelSize() * width * height;
@@ -83,12 +99,18 @@ private static void writeAsPNG(PackSerializer serializer, Path path, GpuTexture
8399
}
84100
}
85101

86-
serializer.saveTexture(NativeImageUtil.writeToByteArray(image), path);
102+
serializer.saveTexture(NativeImageUtil.writeToByteArray(image), path).join();
103+
lock.lock();
104+
try {
105+
condition.signalAll();
106+
} finally {
107+
lock.unlock();
108+
}
87109
}
88110
});
111+
} finally {
112+
buffer.close();
89113
}
90-
91-
buffer.close();
92114
};
93115
commandEncoder.copyTextureToBuffer(texture, buffer, 0, writer, 0);
94116
}

rainbow/src/main/java/org/geysermc/rainbow/mapping/animation/AnimationMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public static BedrockAnimationContext mapAnimation(String identifier, String bon
4848
.withAnimation(identifier + ".head", BedrockAnimation.animation()
4949
.withLoopMode(BedrockAnimation.LoopMode.LOOP)
5050
.withBone(bone, headPosition, headRotation, headScale))
51-
.build(), "animation." + identifier + ".hold_first_person", "animation." + identifier + ".hold_third_person", identifier + ".head");
51+
.build(), "animation." + identifier + ".hold_first_person", "animation." + identifier + ".hold_third_person", "animation." + identifier + ".head");
5252
}
5353
}

rainbow/src/main/java/org/geysermc/rainbow/pack/BedrockPack.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ public CompletableFuture<?> save() {
134134
futures.add(item.save(serializer, paths.attachables(), paths.geometry(), paths.animation(), textureSaver));
135135
}
136136

137-
if (paths.zipOutput().isPresent()) {
138-
RainbowIO.safeIO(() -> CodecUtil.tryZipDirectory(paths.packRoot(), paths.zipOutput().get()));
139-
}
140-
141137
if (reporter instanceof AutoCloseable closeable) {
142138
try {
143139
closeable.close();
144140
} catch (Exception ignored) {}
145141
}
146142

147-
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
143+
CompletableFuture<?> packSerializingFinished = CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
144+
if (paths.zipOutput().isPresent()) {
145+
return packSerializingFinished.thenAcceptAsync(object -> RainbowIO.safeIO(() -> CodecUtil.tryZipDirectory(paths.packRoot(), paths.zipOutput().get())));
146+
}
147+
return packSerializingFinished;
148148
}
149149

150150
public int getMappings() {

0 commit comments

Comments
 (0)