152 lines
8.9 KiB
Java
152 lines
8.9 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.joml.Quaternionfc
|
|
* org.joml.Vector3f
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.client.renderer.blockentity;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.math.Axis;
|
|
import java.util.Set;
|
|
import net.minecraft.client.model.BannerFlagModel;
|
|
import net.minecraft.client.model.BannerModel;
|
|
import net.minecraft.client.model.Model;
|
|
import net.minecraft.client.model.geom.EntityModelSet;
|
|
import net.minecraft.client.model.geom.ModelLayers;
|
|
import net.minecraft.client.renderer.Sheets;
|
|
import net.minecraft.client.renderer.SubmitNodeCollector;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
|
import net.minecraft.client.renderer.blockentity.state.BannerRenderState;
|
|
import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
|
|
import net.minecraft.client.renderer.rendertype.RenderTypes;
|
|
import net.minecraft.client.renderer.special.SpecialModelRenderer;
|
|
import net.minecraft.client.renderer.state.CameraRenderState;
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
|
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.BlockPos;
|
|
import net.minecraft.util.Unit;
|
|
import net.minecraft.world.item.DyeColor;
|
|
import net.minecraft.world.level.block.BannerBlock;
|
|
import net.minecraft.world.level.block.WallBannerBlock;
|
|
import net.minecraft.world.level.block.entity.BannerBlockEntity;
|
|
import net.minecraft.world.level.block.entity.BannerPatternLayers;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.RotationSegment;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.joml.Quaternionfc;
|
|
import org.joml.Vector3f;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class BannerRenderer
|
|
implements BlockEntityRenderer<BannerBlockEntity, BannerRenderState> {
|
|
private static final int MAX_PATTERNS = 16;
|
|
private static final float SIZE = 0.6666667f;
|
|
private final MaterialSet materials;
|
|
private final BannerModel standingModel;
|
|
private final BannerModel wallModel;
|
|
private final BannerFlagModel standingFlagModel;
|
|
private final BannerFlagModel wallFlagModel;
|
|
|
|
public BannerRenderer(BlockEntityRendererProvider.Context context) {
|
|
this(context.entityModelSet(), context.materials());
|
|
}
|
|
|
|
public BannerRenderer(SpecialModelRenderer.BakingContext context) {
|
|
this(context.entityModelSet(), context.materials());
|
|
}
|
|
|
|
public BannerRenderer(EntityModelSet modelSet, MaterialSet materials) {
|
|
this.materials = materials;
|
|
this.standingModel = new BannerModel(modelSet.bakeLayer(ModelLayers.STANDING_BANNER));
|
|
this.wallModel = new BannerModel(modelSet.bakeLayer(ModelLayers.WALL_BANNER));
|
|
this.standingFlagModel = new BannerFlagModel(modelSet.bakeLayer(ModelLayers.STANDING_BANNER_FLAG));
|
|
this.wallFlagModel = new BannerFlagModel(modelSet.bakeLayer(ModelLayers.WALL_BANNER_FLAG));
|
|
}
|
|
|
|
@Override
|
|
public BannerRenderState createRenderState() {
|
|
return new BannerRenderState();
|
|
}
|
|
|
|
@Override
|
|
public void extractRenderState(BannerBlockEntity blockEntity, BannerRenderState state, float partialTicks, Vec3 cameraPosition, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress) {
|
|
BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
|
|
state.baseColor = blockEntity.getBaseColor();
|
|
state.patterns = blockEntity.getPatterns();
|
|
BlockState blockState = blockEntity.getBlockState();
|
|
if (blockState.getBlock() instanceof BannerBlock) {
|
|
state.angle = -RotationSegment.convertToDegrees(blockState.getValue(BannerBlock.ROTATION));
|
|
state.standing = true;
|
|
} else {
|
|
state.angle = -blockState.getValue(WallBannerBlock.FACING).toYRot();
|
|
state.standing = false;
|
|
}
|
|
long gameTime = blockEntity.getLevel() != null ? blockEntity.getLevel().getGameTime() : 0L;
|
|
BlockPos blockPos = blockEntity.getBlockPos();
|
|
state.phase = ((float)Math.floorMod((long)(blockPos.getX() * 7 + blockPos.getY() * 9 + blockPos.getZ() * 13) + gameTime, 100L) + partialTicks) / 100.0f;
|
|
}
|
|
|
|
@Override
|
|
public void submit(BannerRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
|
|
BannerFlagModel flagModel;
|
|
BannerModel model;
|
|
if (state.standing) {
|
|
model = this.standingModel;
|
|
flagModel = this.standingFlagModel;
|
|
} else {
|
|
model = this.wallModel;
|
|
flagModel = this.wallFlagModel;
|
|
}
|
|
BannerRenderer.submitBanner(this.materials, poseStack, submitNodeCollector, state.lightCoords, OverlayTexture.NO_OVERLAY, state.angle, model, flagModel, state.phase, state.baseColor, state.patterns, state.breakProgress, 0);
|
|
}
|
|
|
|
public void submitSpecial(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, DyeColor baseColor, BannerPatternLayers patterns, int outlineColor) {
|
|
BannerRenderer.submitBanner(this.materials, poseStack, submitNodeCollector, lightCoords, overlayCoords, 0.0f, this.standingModel, this.standingFlagModel, 0.0f, baseColor, patterns, null, outlineColor);
|
|
}
|
|
|
|
private static void submitBanner(MaterialSet materials, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, float angle, BannerModel model, BannerFlagModel flagModel, float phase, DyeColor baseColor, BannerPatternLayers patterns, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress, int outlineColor) {
|
|
poseStack.pushPose();
|
|
poseStack.translate(0.5f, 0.0f, 0.5f);
|
|
poseStack.mulPose((Quaternionfc)Axis.YP.rotationDegrees(angle));
|
|
poseStack.scale(0.6666667f, -0.6666667f, -0.6666667f);
|
|
Material material = ModelBakery.BANNER_BASE;
|
|
submitNodeCollector.submitModel(model, Unit.INSTANCE, poseStack, material.renderType(RenderTypes::entitySolid), lightCoords, overlayCoords, -1, materials.get(material), outlineColor, breakProgress);
|
|
BannerRenderer.submitPatterns(materials, poseStack, submitNodeCollector, lightCoords, overlayCoords, flagModel, Float.valueOf(phase), material, true, baseColor, patterns, false, breakProgress, outlineColor);
|
|
poseStack.popPose();
|
|
}
|
|
|
|
public static <S> void submitPatterns(MaterialSet materials, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, Model<S> model, S state, Material baseMaterial, boolean banner, DyeColor baseColor, BannerPatternLayers patterns, boolean hasFoil, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress, int outlineColor) {
|
|
submitNodeCollector.submitModel(model, state, poseStack, baseMaterial.renderType(RenderTypes::entitySolid), lightCoords, overlayCoords, -1, materials.get(baseMaterial), outlineColor, breakProgress);
|
|
if (hasFoil) {
|
|
submitNodeCollector.submitModel(model, state, poseStack, RenderTypes.entityGlint(), lightCoords, overlayCoords, -1, materials.get(baseMaterial), 0, breakProgress);
|
|
}
|
|
BannerRenderer.submitPatternLayer(materials, poseStack, submitNodeCollector, lightCoords, overlayCoords, model, state, banner ? Sheets.BANNER_BASE : Sheets.SHIELD_BASE, baseColor, breakProgress);
|
|
for (int maskIndex = 0; maskIndex < 16 && maskIndex < patterns.layers().size(); ++maskIndex) {
|
|
BannerPatternLayers.Layer layer = patterns.layers().get(maskIndex);
|
|
Material material = banner ? Sheets.getBannerMaterial(layer.pattern()) : Sheets.getShieldMaterial(layer.pattern());
|
|
BannerRenderer.submitPatternLayer(materials, poseStack, submitNodeCollector, lightCoords, overlayCoords, model, state, material, layer.color(), null);
|
|
}
|
|
}
|
|
|
|
private static <S> void submitPatternLayer(MaterialSet materials, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, int overlayCoords, Model<S> model, S state, Material material, DyeColor color, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress) {
|
|
int diffuseColor = color.getTextureDiffuseColor();
|
|
submitNodeCollector.submitModel(model, state, poseStack, material.renderType(RenderTypes::entityNoOutline), lightCoords, overlayCoords, diffuseColor, materials.get(material), 0, breakProgress);
|
|
}
|
|
|
|
public void getExtents(Set<Vector3f> result) {
|
|
PoseStack poseStack = new PoseStack();
|
|
poseStack.translate(0.5f, 0.0f, 0.5f);
|
|
poseStack.scale(0.6666667f, -0.6666667f, -0.6666667f);
|
|
this.standingModel.root().getExtentsForGui(poseStack, result);
|
|
this.standingFlagModel.setupAnim(Float.valueOf(0.0f));
|
|
this.standingFlagModel.root().getExtentsForGui(poseStack, result);
|
|
}
|
|
}
|
|
|