Jump to content

Translucent Blocks and Entities appear invisible through custom translucent entity


Recommended Posts

Posted

I have a mod that adds a custom slime variant. I stuck closely to the methods the normal slime is using, and made a pretty similar renderer, as well as an outer layer. Now, this works, I get a slime with opaque organs and a transparent hull. Looking through the hull, however, all blocks and entities that are also translucent simply stop rendering, and i really dont know why.

This is my slime-renderer:

package com.matnx.earth.entity.render;

import com.matnx.earth.Earth;
import com.matnx.earth.entity.classes.TropicalSlime;
import com.matnx.earth.entity.model.TropicalSlimeCore;
import com.matnx.earth.entity.model.TropicalSlimeModel;
import com.matnx.earth.entity.model.TropicalSlimeShell;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.monster.Slime;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class TropicalSlimeRender extends MobRenderer<TropicalSlime, TropicalSlimeModel<TropicalSlime>> {

    private static final ResourceLocation SLIME_LOCATION = new ResourceLocation(Earth.MODID, "textures/entity/slime/tropical_slime.png");

    public TropicalSlimeRender(EntityRendererProvider.Context p_174391_) {
        super(p_174391_, new TropicalSlimeModel<>(p_174391_.bakeLayer(TropicalSlimeModel.LAYER_LOCATION)), 0.25F);
        this.addLayer(new TropicalSlimeShell<>(this, p_174391_.getModelSet()));
        this.addLayer(new TropicalSlimeCore(this, p_174391_.getModelSet()));
    }

    public void render(TropicalSlime p_115976_, float p_115977_, float p_115978_, PoseStack p_115979_, MultiBufferSource p_115980_, int p_115981_) {
        this.shadowRadius = 0.25F;
        super.render(p_115976_, p_115977_, p_115978_, p_115979_, p_115980_, p_115981_);
        }

    protected void scale(TropicalSlime p_115983_, PoseStack p_115984_, float p_115985_) {
        float f = 0.999F;
        p_115984_.scale(0.999F, 0.999F, 0.999F);
        p_115984_.translate(0.0D, (double)0.001F, 0.0D);
        float f1 = 2;
        float f2 = Mth.lerp(p_115985_, p_115983_.oSquish, p_115983_.squish) / (f1 * 0.5F + 1.0F);
        float f3 = 1.0F / (f2 + 1.0F);
        p_115984_.scale(f3 * f1, 1.0F / f3 * f1, f3 * f1);
    }

    public ResourceLocation getTextureLocation(TropicalSlime p_115974_) {
        return SLIME_LOCATION;
    }
}

This is my OuterLayer

package com.matnx.earth.entity.model;

import com.matnx.earth.Earth;
import com.matnx.earth.ModRenderTypes;
import com.matnx.earth.entity.classes.SkeletonWolf;
import com.matnx.earth.entity.classes.TropicalSlime;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.animation.AnimationChannel;
import net.minecraft.client.animation.AnimationDefinition;
import net.minecraft.client.animation.Keyframe;
import net.minecraft.client.animation.KeyframeAnimations;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.SlimeModel;
import net.minecraft.client.model.geom.*;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.model.geom.builders.PartDefinition;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class TropicalSlimeShell<T extends LivingEntity> extends RenderLayer<T, TropicalSlimeModel<T>> {
    private final EntityModel<T> model;

    public TropicalSlimeShell(RenderLayerParent<T, TropicalSlimeModel<T>> p_174536_, EntityModelSet p_174537_) {
        super(p_174536_);
        this.model = new TropicalSlimeModel<>(p_174537_.bakeLayer(TropicalSlimeModel.SHELL_LOCATION));
    }

    public void render(PoseStack p_117470_, MultiBufferSource p_117471_, int p_117472_, T p_117473_, float p_117474_, float p_117475_, float p_117476_, float p_117477_, float p_117478_, float p_117479_) {
        Minecraft minecraft = Minecraft.getInstance();
        boolean flag = minecraft.shouldEntityAppearGlowing(p_117473_) && p_117473_.isInvisible();
        if (!p_117473_.isInvisible() || flag) {
            VertexConsumer vertexconsumer;
            if (flag) {
                vertexconsumer = p_117471_.getBuffer(RenderType.outline(this.getTextureLocation(p_117473_)));
            } else {
                vertexconsumer = p_117471_.getBuffer(RenderType.entityTranslucent(this.getTextureLocation(p_117473_)));
            }

            this.getParentModel().copyPropertiesTo(this.model);
            this.model.prepareMobModel(p_117473_, p_117474_, p_117475_, p_117476_);
            this.model.setupAnim(p_117473_, p_117474_, p_117475_, p_117477_, p_117478_, p_117479_);
            this.model.renderToBuffer(p_117470_, vertexconsumer, p_117472_, LivingEntityRenderer.getOverlayCoords(p_117473_, 0.0F), 1.0F, 1.0F, 1.0F, 1.0F);
        }
    }
    }

 

Posted

1) Don't use @OnlyIn. You should never have a reason to use that annotation.

2) Most likely this comes down to your texture and the way you render the model/layers. What is transparent and what is opaque? The opaque parts should be rendered in the main model, followed by the translucent parts in the layers going from inner to outer.

Posted

1) The only in comes from the Minecraft source, I can remove it.

2) That's not the problem. The model itself renders as it should. Looking through the translucent layers, like a window, however, other entities and blocks like ice or water, or stained glass become invisible.

Posted

2) Well, that could be a result of the ordering as I mentioned. Another issue could be that anything with an alpha transparency of less than 0.1 gets discarded by the entity translucent shader, so you may need to add one in that doesn't have that restriction.

Posted

That might actually be it, thank you! Replacing the entity translucent shader with the entity translucent emissive shader has everything render correctly. I'll use this as a base for my own implementation. Thanks for the help, I wouldn't have figured that one out.

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.