| 1 | package net.minecraft.client.renderer.special;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 6 | import java.util.function.Consumer;
|
| 7 | import net.fabricmc.api.EnvType;
|
| 8 | import net.fabricmc.api.Environment;
|
| 9 | import net.minecraft.client.model.geom.ModelLayerLocation;
|
| 10 | import net.minecraft.client.model.geom.ModelLayers;
|
| 11 | import net.minecraft.client.model.object.statue.CopperGolemStatueModel;
|
| 12 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 13 | import net.minecraft.resources.Identifier;
|
| 14 | import net.minecraft.util.Unit;
|
| 15 | import net.minecraft.world.entity.animal.golem.CopperGolemOxidationLevels;
|
| 16 | import net.minecraft.world.level.block.CopperGolemStatueBlock.Pose;
|
| 17 | import net.minecraft.world.level.block.WeatheringCopper.WeatherState;
|
| 18 | import org.joml.Vector3fc;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class CopperGolemStatueSpecialRenderer implements NoDataSpecialModelRenderer {
|
| 22 | private final CopperGolemStatueModel model;
|
| 23 | private final Identifier texture;
|
| 24 |
|
| 25 | public CopperGolemStatueSpecialRenderer(final CopperGolemStatueModel model, final Identifier texture) {
|
| 26 | this.model = model;
|
| 27 | this.texture = texture;
|
| 28 | }
|
| 29 |
|
| 30 | @Override
|
| 31 | public void submit(
|
| 32 | final PoseStack poseStack,
|
| 33 | final SubmitNodeCollector submitNodeCollector,
|
| 34 | final int lightCoords,
|
| 35 | final int overlayCoords,
|
| 36 | final boolean hasFoil,
|
| 37 | final int outlineColor
|
| 38 | ) {
|
| 39 | submitNodeCollector.submitModel(this.model, Unit.INSTANCE, poseStack, this.texture, lightCoords, overlayCoords, outlineColor);
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | public void getExtents(final Consumer<Vector3fc> output) {
|
| 44 | PoseStack poseStack = new PoseStack();
|
| 45 | this.model.setupAnim(Unit.INSTANCE);
|
| 46 | this.model.root().getExtentsForGui(poseStack, output);
|
| 47 | }
|
| 48 |
|
| 49 | @Environment(EnvType.CLIENT)
|
| 50 | public record Unbaked(Identifier texture, Pose pose) implements NoDataSpecialModelRenderer.Unbaked {
|
| 51 | public static final MapCodec<CopperGolemStatueSpecialRenderer.Unbaked> MAP_CODEC = RecordCodecBuilder.mapCodec(
|
| 52 | i -> i.group(
|
| 53 | Identifier.CODEC.fieldOf("texture").forGetter(CopperGolemStatueSpecialRenderer.Unbaked::texture),
|
| 54 | Pose.CODEC.fieldOf("pose").forGetter(CopperGolemStatueSpecialRenderer.Unbaked::pose)
|
| 55 | )
|
| 56 | .apply(i, CopperGolemStatueSpecialRenderer.Unbaked::new)
|
| 57 | );
|
| 58 |
|
| 59 | public Unbaked(final WeatherState state, final Pose pose) {
|
| 60 | this(CopperGolemOxidationLevels.getOxidationLevel(state).texture(), pose);
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public MapCodec<CopperGolemStatueSpecialRenderer.Unbaked> type() {
|
| 65 | return MAP_CODEC;
|
| 66 | }
|
| 67 |
|
| 68 | public CopperGolemStatueSpecialRenderer bake(final SpecialModelRenderer.BakingContext context) {
|
| 69 | CopperGolemStatueModel model = new CopperGolemStatueModel(context.entityModelSet().bakeLayer(getModel(this.pose)));
|
| 70 | return new CopperGolemStatueSpecialRenderer(model, this.texture);
|
| 71 | }
|
| 72 |
|
| 73 | private static ModelLayerLocation getModel(final Pose pose) {
|
| 74 | return switch (pose) {
|
| 75 | case STANDING -> ModelLayers.COPPER_GOLEM;
|
| 76 | case SITTING -> ModelLayers.COPPER_GOLEM_SITTING;
|
| 77 | case STAR -> ModelLayers.COPPER_GOLEM_STAR;
|
| 78 | case RUNNING -> ModelLayers.COPPER_GOLEM_RUNNING;
|
| 79 | };
|
| 80 | }
|
| 81 | }
|
| 82 | }
|
| 83 |
|