2025-11-24 22:52:51 +03:00

231 lines
8.2 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* org.joml.Matrix4f
* org.joml.Matrix4fc
* org.joml.Vector3f
* org.joml.Vector3fc
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.renderer.item;
import com.mojang.blaze3d.vertex.PoseStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemTransform;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.special.SpecialModelRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.phys.AABB;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.jspecify.annotations.Nullable;
public class ItemStackRenderState {
ItemDisplayContext displayContext = ItemDisplayContext.NONE;
private int activeLayerCount;
private boolean animated;
private boolean oversizedInGui;
private @Nullable AABB cachedModelBoundingBox;
private LayerRenderState[] layers = new LayerRenderState[]{new LayerRenderState()};
public void ensureCapacity(int requestedCount) {
int requiredNewCapacity = this.activeLayerCount + requestedCount;
int currentCapacity = this.layers.length;
if (requiredNewCapacity > currentCapacity) {
this.layers = Arrays.copyOf(this.layers, requiredNewCapacity);
for (int i = currentCapacity; i < requiredNewCapacity; ++i) {
this.layers[i] = new LayerRenderState();
}
}
}
public LayerRenderState newLayer() {
this.ensureCapacity(1);
return this.layers[this.activeLayerCount++];
}
public void clear() {
this.displayContext = ItemDisplayContext.NONE;
for (int i = 0; i < this.activeLayerCount; ++i) {
this.layers[i].clear();
}
this.activeLayerCount = 0;
this.animated = false;
this.oversizedInGui = false;
this.cachedModelBoundingBox = null;
}
public void setAnimated() {
this.animated = true;
}
public boolean isAnimated() {
return this.animated;
}
public void appendModelIdentityElement(Object element) {
}
private LayerRenderState firstLayer() {
return this.layers[0];
}
public boolean isEmpty() {
return this.activeLayerCount == 0;
}
public boolean usesBlockLight() {
return this.firstLayer().usesBlockLight;
}
public @Nullable TextureAtlasSprite pickParticleIcon(RandomSource randomSource) {
if (this.activeLayerCount == 0) {
return null;
}
return this.layers[randomSource.nextInt((int)this.activeLayerCount)].particleIcon;
}
public void visitExtents(Consumer<Vector3fc> output) {
Vector3f scratch = new Vector3f();
PoseStack.Pose pose = new PoseStack.Pose();
for (int i = 0; i < this.activeLayerCount; ++i) {
Vector3f[] layerExtents;
LayerRenderState layer = this.layers[i];
layer.transform.apply(this.displayContext.leftHand(), pose);
Matrix4f poseTransform = pose.pose();
for (Vector3f extent : layerExtents = layer.extents.get()) {
output.accept((Vector3fc)scratch.set((Vector3fc)extent).mulPosition((Matrix4fc)poseTransform));
}
pose.setIdentity();
}
}
public void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, int outlineColor) {
for (int i = 0; i < this.activeLayerCount; ++i) {
this.layers[i].submit(poseStack, submitNodeCollector, lightCoords, overlayCoords, outlineColor);
}
}
public AABB getModelBoundingBox() {
AABB aabb;
if (this.cachedModelBoundingBox != null) {
return this.cachedModelBoundingBox;
}
AABB.Builder collector = new AABB.Builder();
this.visitExtents(collector::include);
this.cachedModelBoundingBox = aabb = collector.build();
return aabb;
}
public void setOversizedInGui(boolean oversizedInGui) {
this.oversizedInGui = oversizedInGui;
}
public boolean isOversizedInGui() {
return this.oversizedInGui;
}
public class LayerRenderState {
private static final Vector3f[] NO_EXTENTS = new Vector3f[0];
public static final Supplier<Vector3f[]> NO_EXTENTS_SUPPLIER = () -> NO_EXTENTS;
private final List<BakedQuad> quads = new ArrayList<BakedQuad>();
private boolean usesBlockLight;
private @Nullable TextureAtlasSprite particleIcon;
private ItemTransform transform = ItemTransform.NO_TRANSFORM;
private @Nullable RenderType renderType;
private FoilType foilType = FoilType.NONE;
private int[] tintLayers = new int[0];
private @Nullable SpecialModelRenderer<Object> specialRenderer;
private @Nullable Object argumentForSpecialRendering;
private Supplier<Vector3f[]> extents = NO_EXTENTS_SUPPLIER;
public void clear() {
this.quads.clear();
this.renderType = null;
this.foilType = FoilType.NONE;
this.specialRenderer = null;
this.argumentForSpecialRendering = null;
Arrays.fill(this.tintLayers, -1);
this.usesBlockLight = false;
this.particleIcon = null;
this.transform = ItemTransform.NO_TRANSFORM;
this.extents = NO_EXTENTS_SUPPLIER;
}
public List<BakedQuad> prepareQuadList() {
return this.quads;
}
public void setRenderType(RenderType renderType) {
this.renderType = renderType;
}
public void setUsesBlockLight(boolean usesBlockLight) {
this.usesBlockLight = usesBlockLight;
}
public void setExtents(Supplier<Vector3f[]> extents) {
this.extents = extents;
}
public void setParticleIcon(TextureAtlasSprite particleIcon) {
this.particleIcon = particleIcon;
}
public void setTransform(ItemTransform transform) {
this.transform = transform;
}
public <T> void setupSpecialModel(SpecialModelRenderer<T> renderer, @Nullable T argument) {
this.specialRenderer = LayerRenderState.eraseSpecialRenderer(renderer);
this.argumentForSpecialRendering = argument;
}
private static SpecialModelRenderer<Object> eraseSpecialRenderer(SpecialModelRenderer<?> renderer) {
return renderer;
}
public void setFoilType(FoilType foilType) {
this.foilType = foilType;
}
public int[] prepareTintLayers(int activeTints) {
if (activeTints > this.tintLayers.length) {
this.tintLayers = new int[activeTints];
Arrays.fill(this.tintLayers, -1);
}
return this.tintLayers;
}
private void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, int outlineColor) {
poseStack.pushPose();
this.transform.apply(ItemStackRenderState.this.displayContext.leftHand(), poseStack.last());
if (this.specialRenderer != null) {
this.specialRenderer.submit(this.argumentForSpecialRendering, ItemStackRenderState.this.displayContext, poseStack, submitNodeCollector, lightCoords, overlayCoords, this.foilType != FoilType.NONE, outlineColor);
} else if (this.renderType != null) {
submitNodeCollector.submitItem(poseStack, ItemStackRenderState.this.displayContext, lightCoords, overlayCoords, outlineColor, this.tintLayers, this.quads, this.renderType, this.foilType);
}
poseStack.popPose();
}
}
public static enum FoilType {
NONE,
STANDARD,
SPECIAL;
}
}