| 1 | package net.minecraft.client.renderer.entity;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.model.geom.ModelLayers;
|
| 7 | import net.minecraft.client.model.monster.slime.SmallSulfurCubeModel;
|
| 8 | import net.minecraft.client.model.monster.slime.SulfurCubeModel;
|
| 9 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 10 | import net.minecraft.client.renderer.block.BlockModelResolver;
|
| 11 | import net.minecraft.client.renderer.block.model.BlockDisplayContext;
|
| 12 | import net.minecraft.client.renderer.entity.layers.CustomHeadLayer;
|
| 13 | import net.minecraft.client.renderer.entity.layers.SulfurCubeInnerLayer;
|
| 14 | import net.minecraft.client.renderer.entity.state.SulfurCubeRenderState;
|
| 15 | import net.minecraft.client.renderer.state.level.CameraRenderState;
|
| 16 | import net.minecraft.core.component.DataComponents;
|
| 17 | import net.minecraft.resources.Identifier;
|
| 18 | import net.minecraft.world.entity.monster.cubemob.SulfurCube;
|
| 19 | import net.minecraft.world.item.BlockItem;
|
| 20 | import net.minecraft.world.item.ItemStack;
|
| 21 | import net.minecraft.world.item.component.BlockItemStateProperties;
|
| 22 | import net.minecraft.world.level.block.AbstractSkullBlock;
|
| 23 | import net.minecraft.world.level.block.Block;
|
| 24 | import net.minecraft.world.level.block.state.BlockState;
|
| 25 |
|
| 26 | @Environment(EnvType.CLIENT)
|
| 27 | public class SulfurCubeRenderer extends AbstractCubeMobRenderer<SulfurCube, SulfurCubeRenderState, SulfurCubeModel> {
|
| 28 | private static final Identifier SULFUR_CUBE_LOCATION = Identifier.withDefaultNamespace("textures/entity/sulfur_cube/sulfur_cube_outer.png");
|
| 29 | private static final Identifier SULFUR_CUBE_SMALL_LOCATION = Identifier.withDefaultNamespace("textures/entity/sulfur_cube/sulfur_cube_outer_small.png");
|
| 30 | public static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create();
|
| 31 | private static final float COUNTER_SKULL_SCALE = 0.84210527F;
|
| 32 | public static final CustomHeadLayer.Transforms CUSTOM_HEAD_TRANSFORMS = new CustomHeadLayer.Transforms(
|
| 33 | 0.0F, 0.625F, 0.84210527F, 0.84210527F, CustomHeadLayer.Transforms.CUTOUT_PLAYER_SKIN_RESOLVER
|
| 34 | );
|
| 35 | private final SulfurCubeModel normalModel;
|
| 36 | private final SmallSulfurCubeModel smallModel;
|
| 37 | private final BlockModelResolver blockModelResolver;
|
| 38 |
|
| 39 | public SulfurCubeRenderer(final EntityRendererProvider.Context context) {
|
| 40 | SulfurCubeModel normalModel = new SulfurCubeModel(context.bakeLayer(ModelLayers.SULFUR_CUBE));
|
| 41 | super(context, normalModel);
|
| 42 | this.normalModel = normalModel;
|
| 43 | this.smallModel = new SmallSulfurCubeModel(context.bakeLayer(ModelLayers.SULFUR_CUBE_SMALL));
|
| 44 | this.blockModelResolver = context.getBlockModelResolver();
|
| 45 | this.addLayer(new SulfurCubeInnerLayer(this, context.getModelSet()));
|
| 46 | this.addLayer(new CustomHeadLayer<>(this, context.getModelSet(), context.getPlayerSkinRenderCache(), CUSTOM_HEAD_TRANSFORMS));
|
| 47 | }
|
| 48 |
|
| 49 | public void submit(final SulfurCubeRenderState state, final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final CameraRenderState camera) {
|
| 50 | this.model = state.isBaby ? this.smallModel : this.normalModel;
|
| 51 | super.submit(state, poseStack, submitNodeCollector, camera);
|
| 52 | }
|
| 53 |
|
| 54 | protected void scale(final SulfurCubeRenderState state, final PoseStack poseStack) {
|
| 55 | this.downscaleSlightly(poseStack);
|
| 56 | super.scale(state, poseStack);
|
| 57 | float fuse = state.fuseRemainingTicks;
|
| 58 | if (fuse < 10.0F && fuse > 0.0F) {
|
| 59 | float s = 1.0F + TntRenderer.getSwellAmount(fuse);
|
| 60 | poseStack.scale(s, s, s);
|
| 61 | }
|
| 62 |
|
| 63 | float vOffset = state.isBaby ? 1.24F : 0.98F;
|
| 64 | float extraDownscale = state.isBaby ? 1.0F : 0.5F;
|
| 65 | float onePixelUpIfVisible = (state.isInvisible ? 0.0F : 1.0F) / 16.0F;
|
| 66 | poseStack.scale(extraDownscale, extraDownscale, extraDownscale);
|
| 67 | poseStack.translate(-0.0F, vOffset - onePixelUpIfVisible, -0.0F);
|
| 68 | }
|
| 69 |
|
| 70 | public Identifier getTextureLocation(final SulfurCubeRenderState state) {
|
| 71 | return state.isBaby ? SULFUR_CUBE_SMALL_LOCATION : SULFUR_CUBE_LOCATION;
|
| 72 | }
|
| 73 |
|
| 74 | public SulfurCubeRenderState createRenderState() {
|
| 75 | return new SulfurCubeRenderState();
|
| 76 | }
|
| 77 |
|
| 78 | public void extractRenderState(final SulfurCube entity, final SulfurCubeRenderState state, final float partialTicks) {
|
| 79 | super.extractRenderState(entity, state, partialTicks);
|
| 80 | state.fuseRemainingTicks = entity.isPrimed() ? entity.getFuse() - partialTicks + 1.0F : 0.0F;
|
| 81 | ItemStack containedBlock = entity.getBodyArmorItem();
|
| 82 | if (!containedBlock.isEmpty()) {
|
| 83 | if (containedBlock.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof AbstractSkullBlock skullBlock) {
|
| 84 | state.wornHeadType = skullBlock.getType();
|
| 85 | state.wornHeadProfile = containedBlock.get(DataComponents.PROFILE);
|
| 86 | } else {
|
| 87 | BlockItemStateProperties blockItemState = containedBlock.getOrDefault(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY);
|
| 88 | BlockState blockState = blockItemState.apply(Block.byItem(containedBlock.getItem()).defaultBlockState());
|
| 89 | this.blockModelResolver.update(state.containedBlock, blockState, BLOCK_DISPLAY_CONTEXT);
|
| 90 | }
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 | protected void applySizeAndSquish(final SulfurCubeRenderState state, final PoseStack poseStack) {
|
| 95 | float size = state.size;
|
| 96 | float ss = state.containedBlock.isEmpty() ? state.squish / (size * 0.5F + 1.0F) : 0.0F;
|
| 97 | float w = 1.0F / (ss + 1.0F);
|
| 98 | poseStack.scale(w * size, 1.0F / w * size, w * size);
|
| 99 | }
|
| 100 | }
|
| 101 |
|