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

88 lines
3.9 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.serialization.MapCodec
* org.joml.Vector3f
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.renderer.special;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.serialization.MapCodec;
import java.util.Objects;
import java.util.Set;
import net.minecraft.client.model.ShieldModel;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.blockentity.BannerRenderer;
import net.minecraft.client.renderer.special.SpecialModelRenderer;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.MaterialSet;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.util.Unit;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BannerPatternLayers;
import org.joml.Vector3f;
import org.jspecify.annotations.Nullable;
public class ShieldSpecialRenderer
implements SpecialModelRenderer<DataComponentMap> {
private final MaterialSet materials;
private final ShieldModel model;
public ShieldSpecialRenderer(MaterialSet materials, ShieldModel model) {
this.materials = materials;
this.model = model;
}
@Override
public @Nullable DataComponentMap extractArgument(ItemStack stack) {
return stack.immutableComponents();
}
@Override
public void submit(@Nullable DataComponentMap components, ItemDisplayContext type, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, boolean hasFoil, int outlineColor) {
BannerPatternLayers patterns = components != null ? components.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY) : BannerPatternLayers.EMPTY;
DyeColor baseColor = components != null ? components.get(DataComponents.BASE_COLOR) : null;
boolean hasPatterns = !patterns.layers().isEmpty() || baseColor != null;
poseStack.pushPose();
poseStack.scale(1.0f, -1.0f, -1.0f);
Material base = hasPatterns ? ModelBakery.SHIELD_BASE : ModelBakery.NO_PATTERN_SHIELD;
submitNodeCollector.submitModelPart(this.model.handle(), poseStack, this.model.renderType(base.atlasLocation()), lightCoords, overlayCoords, this.materials.get(base), false, false, -1, null, outlineColor);
if (hasPatterns) {
BannerRenderer.submitPatterns(this.materials, poseStack, submitNodeCollector, lightCoords, overlayCoords, this.model, Unit.INSTANCE, base, false, Objects.requireNonNullElse(baseColor, DyeColor.WHITE), patterns, hasFoil, null, outlineColor);
} else {
submitNodeCollector.submitModelPart(this.model.plate(), poseStack, this.model.renderType(base.atlasLocation()), lightCoords, overlayCoords, this.materials.get(base), false, hasFoil, -1, null, outlineColor);
}
poseStack.popPose();
}
@Override
public void getExtents(Set<Vector3f> result) {
PoseStack poseStack = new PoseStack();
poseStack.scale(1.0f, -1.0f, -1.0f);
this.model.root().getExtentsForGui(poseStack, result);
}
public record Unbaked() implements SpecialModelRenderer.Unbaked
{
public static final Unbaked INSTANCE = new Unbaked();
public static final MapCodec<Unbaked> MAP_CODEC = MapCodec.unit((Object)INSTANCE);
public MapCodec<Unbaked> type() {
return MAP_CODEC;
}
@Override
public SpecialModelRenderer<?> bake(SpecialModelRenderer.BakingContext context) {
return new ShieldSpecialRenderer(context.materials(), new ShieldModel(context.entityModelSet().bakeLayer(ModelLayers.SHIELD)));
}
}
}