Fix and improve itemstack renderer
This commit is contained in:
parent
e5b5c399ef
commit
a4dd50bf8d
1 changed files with 23 additions and 13 deletions
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
package reborncore.client;
|
package reborncore.client;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.systems.VertexSorter;
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
@ -39,7 +39,6 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.lwjgl.opengl.GL12;
|
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -58,15 +57,19 @@ public class ItemStackRenderer implements HudRenderCallback {
|
||||||
if (!ItemStackRenderManager.RENDER_QUEUE.isEmpty()) {
|
if (!ItemStackRenderManager.RENDER_QUEUE.isEmpty()) {
|
||||||
ItemStack itemStack = ItemStackRenderManager.RENDER_QUEUE.remove();
|
ItemStack itemStack = ItemStackRenderManager.RENDER_QUEUE.remove();
|
||||||
Identifier id = Registries.ITEM.getId(itemStack.getItem());
|
Identifier id = Registries.ITEM.getId(itemStack.getItem());
|
||||||
drawContext.drawText(MinecraftClient.getInstance().textRenderer, "Rendering " + id + ", " + ItemStackRenderManager.RENDER_QUEUE.size() + " items left", 5, 5, -1, false);
|
drawContext.drawText(MinecraftClient.getInstance().textRenderer, "Rendering " + id, 5, 5, -1, false);
|
||||||
|
drawContext.drawText(MinecraftClient.getInstance().textRenderer, ItemStackRenderManager.RENDER_QUEUE.size() + " items left", 5, 15, -1, false);
|
||||||
export(id, itemStack);
|
export(id, itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void export(Identifier identifier, ItemStack item) {
|
private void export(Identifier identifier, ItemStack item) {
|
||||||
Matrix4f matrix4f = new Matrix4f().setOrtho(0, 16, 0, 16, 1000, 3000);
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
RenderSystem.setProjectionMatrix(matrix4f, null); // TODO 1.20
|
|
||||||
|
Matrix4f matrix4f = new Matrix4f().setOrtho(0, 16, 16, 0, 1000, 3000);
|
||||||
|
RenderSystem.setProjectionMatrix(matrix4f, VertexSorter.BY_Z);
|
||||||
MatrixStack stack = RenderSystem.getModelViewStack();
|
MatrixStack stack = RenderSystem.getModelViewStack();
|
||||||
|
stack.push();
|
||||||
stack.loadIdentity();
|
stack.loadIdentity();
|
||||||
stack.translate(0, 0, -2000);
|
stack.translate(0, 0, -2000);
|
||||||
DiffuseLighting.enableGuiDepthLighting();
|
DiffuseLighting.enableGuiDepthLighting();
|
||||||
|
@ -78,15 +81,20 @@ public class ItemStackRenderer implements HudRenderCallback {
|
||||||
framebuffer.setClearColor(0, 0, 0, 0);
|
framebuffer.setClearColor(0, 0, 0, 0);
|
||||||
framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
|
framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC);
|
||||||
|
|
||||||
|
{
|
||||||
framebuffer.beginWrite(true);
|
framebuffer.beginWrite(true);
|
||||||
GlStateManager._clear(GL12.GL_COLOR_BUFFER_BIT | GL12.GL_DEPTH_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC);
|
DrawContext drawContext = new DrawContext(client, client.getBufferBuilders().getEntityVertexConsumers());
|
||||||
// MinecraftClient.getInstance().getItemRenderer().renderInGui(stack, item, 0, 0); // TODO 1.20
|
drawContext.drawItem(item, 0, 0);
|
||||||
|
drawContext.draw();
|
||||||
framebuffer.endWrite();
|
framebuffer.endWrite();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
framebuffer.beginRead();
|
framebuffer.beginRead();
|
||||||
nativeImage.loadFromTextureImage(0, false);
|
nativeImage.loadFromTextureImage(0, false);
|
||||||
nativeImage.mirrorVertically();
|
nativeImage.mirrorVertically();
|
||||||
framebuffer.endRead();
|
framebuffer.endRead();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path path = FabricLoader.getInstance().getGameDir().resolve("item_renderer").resolve(identifier.getNamespace()).resolve(identifier.getPath() + ".png");
|
Path path = FabricLoader.getInstance().getGameDir().resolve("item_renderer").resolve(identifier.getNamespace()).resolve(identifier.getPath() + ".png");
|
||||||
|
@ -98,5 +106,7 @@ public class ItemStackRenderer implements HudRenderCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
framebuffer.delete();
|
framebuffer.delete();
|
||||||
|
stack.pop();
|
||||||
|
RenderSystem.applyModelViewMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue