106 lines
5.2 KiB
Java
106 lines
5.2 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package net.minecraft.client.renderer.entity;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
import com.mojang.blaze3d.vertex.VertexMultiConsumer;
|
|
import com.mojang.math.MatrixUtil;
|
|
import java.util.List;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
import net.minecraft.client.renderer.Sheets;
|
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
|
import net.minecraft.client.renderer.item.ItemStackRenderState;
|
|
import net.minecraft.client.renderer.rendertype.RenderType;
|
|
import net.minecraft.client.renderer.rendertype.RenderTypes;
|
|
import net.minecraft.resources.Identifier;
|
|
import net.minecraft.util.ARGB;
|
|
import net.minecraft.world.item.ItemDisplayContext;
|
|
|
|
public class ItemRenderer {
|
|
public static final Identifier ENCHANTED_GLINT_ARMOR = Identifier.withDefaultNamespace("textures/misc/enchanted_glint_armor.png");
|
|
public static final Identifier ENCHANTED_GLINT_ITEM = Identifier.withDefaultNamespace("textures/misc/enchanted_glint_item.png");
|
|
public static final float SPECIAL_FOIL_UI_SCALE = 0.5f;
|
|
public static final float SPECIAL_FOIL_FIRST_PERSON_SCALE = 0.75f;
|
|
public static final float SPECIAL_FOIL_TEXTURE_SCALE = 0.0078125f;
|
|
public static final int NO_TINT = -1;
|
|
|
|
public static void renderItem(ItemDisplayContext type, PoseStack poseStack, MultiBufferSource bufferSource, int lightCoords, int overlayCoords, int[] tintLayers, List<BakedQuad> quads, RenderType renderType, ItemStackRenderState.FoilType foilType) {
|
|
VertexConsumer builder;
|
|
if (foilType == ItemStackRenderState.FoilType.SPECIAL) {
|
|
PoseStack.Pose cameraPose = poseStack.last().copy();
|
|
if (type == ItemDisplayContext.GUI) {
|
|
MatrixUtil.mulComponentWise(cameraPose.pose(), 0.5f);
|
|
} else if (type.firstPerson()) {
|
|
MatrixUtil.mulComponentWise(cameraPose.pose(), 0.75f);
|
|
}
|
|
builder = ItemRenderer.getSpecialFoilBuffer(bufferSource, renderType, cameraPose);
|
|
} else {
|
|
builder = ItemRenderer.getFoilBuffer(bufferSource, renderType, true, foilType != ItemStackRenderState.FoilType.NONE);
|
|
}
|
|
ItemRenderer.renderQuadList(poseStack, builder, quads, tintLayers, lightCoords, overlayCoords);
|
|
}
|
|
|
|
private static VertexConsumer getSpecialFoilBuffer(MultiBufferSource bufferSource, RenderType renderType, PoseStack.Pose cameraPose) {
|
|
return VertexMultiConsumer.create((VertexConsumer)new SheetedDecalTextureGenerator(bufferSource.getBuffer(ItemRenderer.useTransparentGlint(renderType) ? RenderTypes.glintTranslucent() : RenderTypes.glint()), cameraPose, 0.0078125f), bufferSource.getBuffer(renderType));
|
|
}
|
|
|
|
public static VertexConsumer getFoilBuffer(MultiBufferSource bufferSource, RenderType renderType, boolean sheeted, boolean hasFoil) {
|
|
if (hasFoil) {
|
|
if (ItemRenderer.useTransparentGlint(renderType)) {
|
|
return VertexMultiConsumer.create(bufferSource.getBuffer(RenderTypes.glintTranslucent()), bufferSource.getBuffer(renderType));
|
|
}
|
|
return VertexMultiConsumer.create(bufferSource.getBuffer(sheeted ? RenderTypes.glint() : RenderTypes.entityGlint()), bufferSource.getBuffer(renderType));
|
|
}
|
|
return bufferSource.getBuffer(renderType);
|
|
}
|
|
|
|
public static List<RenderType> getFoilRenderTypes(RenderType baseRenderType, boolean sheeted, boolean hasFoil) {
|
|
if (hasFoil) {
|
|
if (ItemRenderer.useTransparentGlint(baseRenderType)) {
|
|
return List.of(baseRenderType, RenderTypes.glintTranslucent());
|
|
}
|
|
return List.of(baseRenderType, sheeted ? RenderTypes.glint() : RenderTypes.entityGlint());
|
|
}
|
|
return List.of(baseRenderType);
|
|
}
|
|
|
|
private static boolean useTransparentGlint(RenderType renderType) {
|
|
return Minecraft.useShaderTransparency() && (renderType == Sheets.translucentItemSheet() || renderType == Sheets.translucentBlockItemSheet());
|
|
}
|
|
|
|
private static int getLayerColorSafe(int[] layers, int layer) {
|
|
if (layer < 0 || layer >= layers.length) {
|
|
return -1;
|
|
}
|
|
return layers[layer];
|
|
}
|
|
|
|
private static void renderQuadList(PoseStack poseStack, VertexConsumer builder, List<BakedQuad> quads, int[] tintLayers, int lightCoords, int overlayCoords) {
|
|
PoseStack.Pose pose = poseStack.last();
|
|
for (BakedQuad quad : quads) {
|
|
float blue;
|
|
float green;
|
|
float red;
|
|
float alpha;
|
|
if (quad.isTinted()) {
|
|
int color = ItemRenderer.getLayerColorSafe(tintLayers, quad.tintIndex());
|
|
alpha = (float)ARGB.alpha(color) / 255.0f;
|
|
red = (float)ARGB.red(color) / 255.0f;
|
|
green = (float)ARGB.green(color) / 255.0f;
|
|
blue = (float)ARGB.blue(color) / 255.0f;
|
|
} else {
|
|
alpha = 1.0f;
|
|
red = 1.0f;
|
|
green = 1.0f;
|
|
blue = 1.0f;
|
|
}
|
|
builder.putBulkData(pose, quad, red, green, blue, alpha, lightCoords, overlayCoords);
|
|
}
|
|
}
|
|
}
|
|
|