Defer renderer item stack creation
This commit is contained in:
+26
-10
@@ -23,6 +23,7 @@ import net.minecraft.core.component.DataComponents;
|
|||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
public final class RenderCatalogClient implements ClientModInitializer {
|
public final class RenderCatalogClient implements ClientModInitializer {
|
||||||
@@ -104,16 +105,12 @@ public final class RenderCatalogClient implements ClientModInitializer {
|
|||||||
String renderPath = renderPathElement.getAsString();
|
String renderPath = renderPathElement.getAsString();
|
||||||
String customName = customNameElement != null && customNameElement.isJsonPrimitive() ? customNameElement.getAsString() : null;
|
String customName = customNameElement != null && customNameElement.isJsonPrimitive() ? customNameElement.getAsString() : null;
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(BuiltInRegistries.ITEM.getValue(Identifier.withDefaultNamespace(itemId)));
|
Item item = BuiltInRegistries.ITEM.getValue(Identifier.withDefaultNamespace(itemId));
|
||||||
if (stack.isEmpty()) {
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customName != null) {
|
jobs.add(new RenderJob(renderPath, item, customName));
|
||||||
stack.set(DataComponents.CUSTOM_NAME, Component.literal(customName));
|
|
||||||
}
|
|
||||||
|
|
||||||
jobs.add(new RenderJob(renderPath, stack));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path readPathEnv(String key) {
|
private Path readPathEnv(String key) {
|
||||||
@@ -198,7 +195,20 @@ public final class RenderCatalogClient implements ClientModInitializer {
|
|||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private record RenderJob(String outputPath, ItemStack stack) {
|
private ItemStack createStack(RenderJob job) {
|
||||||
|
ItemStack stack = new ItemStack(job.item());
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (job.customName() != null) {
|
||||||
|
stack.set(DataComponents.CUSTOM_NAME, Component.literal(job.customName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record RenderJob(String outputPath, Item item, String customName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class RenderScreen extends Screen {
|
private final class RenderScreen extends Screen {
|
||||||
@@ -222,12 +232,18 @@ public final class RenderCatalogClient implements ClientModInitializer {
|
|||||||
context.fill(0, 0, width, height, 0x00000000);
|
context.fill(0, 0, width, height, 0x00000000);
|
||||||
|
|
||||||
if (currentJobIndex < jobs.size()) {
|
if (currentJobIndex < jobs.size()) {
|
||||||
|
Minecraft client = Minecraft.getInstance();
|
||||||
RenderJob job = jobs.get(currentJobIndex);
|
RenderJob job = jobs.get(currentJobIndex);
|
||||||
context.item(job.stack(), (width / 2) - 8, (height / 2) - 8);
|
ItemStack stack = createStack(job);
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
client.execute(() -> advanceJob());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.item(stack, (width / 2) - 8, (height / 2) - 8);
|
||||||
|
|
||||||
if (!captureQueued) {
|
if (!captureQueued) {
|
||||||
captureQueued = true;
|
captureQueued = true;
|
||||||
Minecraft client = Minecraft.getInstance();
|
|
||||||
client.execute(() -> renderCurrentJob(client, this));
|
client.execute(() -> renderCurrentJob(client, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user