Jump to content

[1.15.2]Block doesn't render properly on Mooshroom's back


NonToxicEel

Recommended Posts

So I basically wanna make a mod that generates mooshrooms with mushrooms that have different colors on their back. But my progress stuck as it seems like that Minecraft render has issues dealing with colored blocks. Here are my codes:

public class RendererResourceMooshroom extends MobRenderer<EntityResourceMooshroom, CowModel<EntityResourceMooshroom>> {

    Block mushroom;

    public RendererResourceMooshroom(EntityRendererManager renderManagerIn, Block mushroom) {
        super(renderManagerIn,new CowModel<>(), 0.7F);
        this.mushroom = mushroom;
        this.addLayer(new ResourceMooshroomLayer<>(this, mushroom));
    }

    @Override
    public ResourceLocation getEntityTexture(EntityResourceMooshroom entity) {
        return new ResourceLocation("textures/entity/cow/brown_mooshroom.png");
    }

    class ResourceMooshroomLayer<T extends EntityResourceMooshroom> extends MooshroomMushroomLayer<T>{
        Block mushroom;
        public ResourceMooshroomLayer(IEntityRenderer rendererIn, Block mushroom) {
            super(rendererIn);
            this.mushroom = mushroom;
        }

        public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn, T entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
            if (!entitylivingbaseIn.isChild() && !entitylivingbaseIn.isInvisible()) {
                BlockRendererDispatcher blockrendererdispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
                BlockState blockstate = mushroom.getDefaultState();
                int i = LivingRenderer.getPackedOverlay(entitylivingbaseIn, 0.0F);
                matrixStackIn.push();
                matrixStackIn.translate(0.2F, -0.35F, 0.5D);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-48.0F));
                matrixStackIn.scale(-1.0F, -1.0F, 1.0F);
                matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
                blockrendererdispatcher.renderBlock(blockstate, matrixStackIn, bufferIn, packedLightIn, i);
                matrixStackIn.pop();
                matrixStackIn.push();
                matrixStackIn.translate(0.2F, -0.35F, 0.5D);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(42.0F));
                matrixStackIn.translate(0.1F, 0.0D, -0.6F);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-48.0F));
                matrixStackIn.scale(-1.0F, -1.0F, 1.0F);
                matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
                blockrendererdispatcher.renderBlock(blockstate, matrixStackIn, bufferIn, packedLightIn, i);
                matrixStackIn.pop();
                matrixStackIn.push();
                this.getEntityModel().getHead().setAnglesAndRotation(matrixStackIn);
                matrixStackIn.translate(0.0D, -0.7F, -0.2F);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-78.0F));
                matrixStackIn.scale(-1.0F, -1.0F, 1.0F);
                matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
                blockrendererdispatcher.renderBlock(blockstate, matrixStackIn, bufferIn, packedLightIn, i);
                matrixStackIn.pop();
            }
        }
    }

}

And it turned out to be without color overlay:

1401531271_QQ20200314013552.png.103eac6e601666b52e1edd2ce3b60faa.png

While I truely want the color be the same as those I placed on the ground:

1192856087_QQ20200314013610.png.f7abada331a96d2b56ab12d5f7a54f89.png

The source code is available on GitHub for anyone who interests in getting more codes:https://github.com/dong031001/Mooshroomcraft

Edited by NonToxicEel
Link to comment
Share on other sites

Overwrote BlockRenderer and rederModel() function; everything turns out fine 'ight now.


public class RendererResourceMooshroom extends MobRenderer<EntityResourceMooshroom, CowModel<EntityResourceMooshroom>> {

    Block mushroom;

    public RendererResourceMooshroom(EntityRendererManager renderManagerIn, Block mushroom) {
        super(renderManagerIn,new CowModel<>(), 0.7F);
        this.mushroom = mushroom;
        this.addLayer(new ResourceMooshroomLayer<>(this, mushroom));
    }

    @Override
    public ResourceLocation getEntityTexture(EntityResourceMooshroom entity) {
        return new ResourceLocation("textures/entity/cow/brown_mooshroom.png");
    }

    class ResourceMooshroomLayer<T extends EntityResourceMooshroom> extends MooshroomMushroomLayer<T>{
        Block mushroom;
        public ResourceMooshroomLayer(IEntityRenderer rendererIn, Block mushroom) {
            super(rendererIn);
            this.mushroom = mushroom;
        }

        public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn, T entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
            if (!entitylivingbaseIn.isChild() && !entitylivingbaseIn.isInvisible()) {
                BlockRendererDispatcher blockrendererdispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
                ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
                BlockState blockstate = mushroom.getDefaultState().getBlockState();
                int i = LivingRenderer.getPackedOverlay(entitylivingbaseIn, 0.0F);
                matrixStackIn.push();
                matrixStackIn.translate(0.2F, -0.35F, 0.5D);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-48.0F));
                matrixStackIn.scale(-1.0F, -1.0F, 1.0F);
                matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
                renderMushroom(blockrendererdispatcher,blockstate, matrixStackIn, bufferIn, packedLightIn, i, net.minecraftforge.client.model.data.EmptyModelData.INSTANCE);

                matrixStackIn.pop();
                matrixStackIn.push();
                matrixStackIn.translate(0.2F, -0.35F, 0.5D);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(42.0F));
                matrixStackIn.translate(0.1F, 0.0D, -0.6F);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-48.0F));
                matrixStackIn.scale(-1.0F, -1.0F, 1.0F);
                matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
                renderMushroom(blockrendererdispatcher,blockstate, matrixStackIn, bufferIn, packedLightIn, i, net.minecraftforge.client.model.data.EmptyModelData.INSTANCE);
                matrixStackIn.pop();
                matrixStackIn.push();
                this.getEntityModel().getHead().translateRotate(matrixStackIn);
                matrixStackIn.translate(0.0D, -0.7F, -0.2F);
                matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-78.0F));
                matrixStackIn.scale(-1.0F, -1.0F, 1.0F);
                matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
                renderMushroom(blockrendererdispatcher,blockstate, matrixStackIn, bufferIn, packedLightIn, i, net.minecraftforge.client.model.data.EmptyModelData.INSTANCE);
                matrixStackIn.pop();
            }
        }

        private void renderMushroom(BlockRendererDispatcher dispatcher, BlockState blockStateIn, MatrixStack matrixStackIn, IRenderTypeBuffer bufferTypeIn, int combinedLightIn, int combinedOverlayIn, net.minecraftforge.client.model.data.IModelData modelData){
            IBakedModel ibakedmodel = dispatcher.getModelForState(blockStateIn);
            int i = ((BlockResourceMushroom) blockStateIn.getBlock()).color;
            float f = (float)(i >> 16 & 255) / 255.0F;
            float f1 = (float)(i >> 8 & 255) / 255.0F;
            float f2 = (float)(i & 255) / 255.0F;
            renderModel(matrixStackIn.getLast(), bufferTypeIn.getBuffer(RenderTypeLookup.getRenderType(blockStateIn)), blockStateIn, ibakedmodel, f, f1, f2, combinedLightIn, combinedOverlayIn, modelData);
        }

        private void renderModel(MatrixStack.Entry matrixEntry, IVertexBuilder buffer, @Nullable BlockState state, IBakedModel modelIn, float red, float green, float blue, int combinedLightIn, int combinedOverlayIn, net.minecraftforge.client.model.data.IModelData modelData){
            Random random = new Random();
            random.setSeed(42L);
            List<BakedQuad> quadList = modelIn.getQuads(state, null, random);
            for(BakedQuad bakedquad : quadList) {
                float f;
                float f1;
                float f2;
                if (bakedquad.getTintIndex()==1) {
                    f = MathHelper.clamp(red, 0.0F, 1.0F);
                    f1 = MathHelper.clamp(green, 0.0F, 1.0F);
                    f2 = MathHelper.clamp(blue, 0.0F, 1.0F);
                } else {
                    f = 1.0F;
                    f1 = 1.0F;
                    f2 = 1.0F;
                }
                buffer.addQuad(matrixEntry, bakedquad, f, f1, f2, combinedLightIn, combinedOverlayIn);
            }
        }
    }

}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.