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

89 lines
3.8 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.datafixers.kinds.App
* com.mojang.datafixers.kinds.Applicative
* com.mojang.serialization.Codec
* com.mojang.serialization.MapCodec
* com.mojang.serialization.codecs.RecordCodecBuilder
* org.joml.Vector3f
* org.jspecify.annotations.Nullable
*/
package net.minecraft.client.renderer.special;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.kinds.App;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Optional;
import java.util.Set;
import net.minecraft.client.model.SkullModelBase;
import net.minecraft.client.renderer.SubmitNodeCollector;
import net.minecraft.client.renderer.blockentity.SkullBlockRenderer;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.special.NoDataSpecialModelRenderer;
import net.minecraft.client.renderer.special.SpecialModelRenderer;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.block.SkullBlock;
import org.joml.Vector3f;
import org.jspecify.annotations.Nullable;
public class SkullSpecialRenderer
implements NoDataSpecialModelRenderer {
private final SkullModelBase model;
private final float animation;
private final RenderType renderType;
public SkullSpecialRenderer(SkullModelBase model, float animation, RenderType renderType) {
this.model = model;
this.animation = animation;
this.renderType = renderType;
}
@Override
public void submit(ItemDisplayContext type, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, boolean hasFoil, int outlineColor) {
SkullBlockRenderer.submitSkull(null, 180.0f, this.animation, poseStack, submitNodeCollector, lightCoords, this.model, this.renderType, outlineColor, null);
}
@Override
public void getExtents(Set<Vector3f> result) {
PoseStack poseStack = new PoseStack();
poseStack.translate(0.5f, 0.0f, 0.5f);
poseStack.scale(-1.0f, -1.0f, 1.0f);
SkullModelBase.State modelState = new SkullModelBase.State();
modelState.animationPos = this.animation;
modelState.yRot = 180.0f;
this.model.setupAnim(modelState);
this.model.root().getExtentsForGui(poseStack, result);
}
public record Unbaked(SkullBlock.Type kind, Optional<Identifier> textureOverride, float animation) implements SpecialModelRenderer.Unbaked
{
public static final MapCodec<Unbaked> MAP_CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)SkullBlock.Type.CODEC.fieldOf("kind").forGetter(Unbaked::kind), (App)Identifier.CODEC.optionalFieldOf("texture").forGetter(Unbaked::textureOverride), (App)Codec.FLOAT.optionalFieldOf("animation", (Object)Float.valueOf(0.0f)).forGetter(Unbaked::animation)).apply((Applicative)i, Unbaked::new));
public Unbaked(SkullBlock.Type kind) {
this(kind, Optional.empty(), 0.0f);
}
public MapCodec<Unbaked> type() {
return MAP_CODEC;
}
@Override
public @Nullable SpecialModelRenderer<?> bake(SpecialModelRenderer.BakingContext context) {
SkullModelBase model = SkullBlockRenderer.createModel(context.entityModelSet(), this.kind);
Identifier textureOverride = this.textureOverride.map(t -> t.withPath(p -> "textures/entity/" + p + ".png")).orElse(null);
if (model == null) {
return null;
}
RenderType renderType = SkullBlockRenderer.getSkullRenderType(this.kind, textureOverride);
return new SkullSpecialRenderer(model, this.animation, renderType);
}
}
}