Jump to content

How can i add my Layer into my Renderer?


Drachenbauer

Recommended Posts

Hello

 

I have an Entity, that needs a Layer-class to show a transparent part (like the vanilla-Slime).

I have the Model-class, the Renderer-class, the Layer-class and the Model-class.

In all of them the class-header, the header of the constructor and the superconstructor-call (if exist) have the same shape like in the Slime-classes, i just use the classes for my own entity, where.the Slime-classes where used.

So i wonder, why i get an error:

Quote

Cannot infer type arguments for CoralFinLayer<>

at this line in the Rendererclass:

this.addLayer(new CoralFinLayer<>(this));

 

Entity-class:

/** 
 ** This is Coral, an angler-fish-character from a not so well known Rovio-game called "Fruit-Nibblers".
 ** I added her here, because her game is from the creators of Angry Birds, too.
 ** I like her look and I think, it maybe a good idea to make her best friends with Stella
 **/

package drachenbauer32.angrybirdsmod.entities;

import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Pose;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.goal.LookAtGoal;
import net.minecraft.entity.ai.goal.LookRandomlyGoal;
import net.minecraft.entity.ai.goal.RandomSwimmingGoal;
import net.minecraft.entity.ai.goal.RandomWalkingGoal;
import net.minecraft.entity.ai.goal.SwimGoal;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class CoralEntity extends AnimalEntity
{
    public CoralEntity(EntityType<? extends CoralEntity> type, World worldIn)
    {
        super(type, worldIn);
    }
    
    @Override
    public AgeableEntity createChild(AgeableEntity arg0)
    {
        return null;
    }
    
    @Override
    public float getEyeHeight(Pose pose)
    {
        return this.getSize(pose).height / 2 + getSize(pose).height / 14;
    }
    
    @Override
    protected void registerGoals()
    {
        this.goalSelector.addGoal(0, new SwimGoal(this));
        this.goalSelector.addGoal(1, new RandomSwimmingGoal(this, 0.2d, 10));
        this.goalSelector.addGoal(2, new RandomWalkingGoal(this, 0.2d));
        this.goalSelector.addGoal(3, new LookAtGoal(this, PlayerEntity.class, 6.0F));
        this.goalSelector.addGoal(4, new LookRandomlyGoal(this));
    }
    
    @Override
    public boolean canBreatheUnderwater()
    {
        return true;
    }
    
    @Override
    protected void registerAttributes()
    {
        super.registerAttributes();
        this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
    }
    
    @OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
        return -45 * ((float)Math.PI / 180) + (this.getHealth() / this.getMaxHealth() * 60 * ((float)Math.PI / 180));
    }
}

Does it matter, that my Entity extends AnimalEntity, while the Slime extends MobEntity?

 

Renderer-class (with the error):

package drachenbauer32.angrybirdsmod.entities.renderers;

import drachenbauer32.angrybirdsmod.entities.CoralEntity;
import drachenbauer32.angrybirdsmod.entities.layers.CoralFinLayer;
import drachenbauer32.angrybirdsmod.entities.models.CoralModel;
import drachenbauer32.angrybirdsmod.util.Reference;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.util.ResourceLocation;

public class CoralRenderer extends MobRenderer<CoralEntity, EntityModel<CoralEntity>>
{
    private static final ResourceLocation CORAL_TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/entity/coral.png");
    private static final CoralModel<CoralEntity> CORAL_MODEL = new CoralModel<>(false);
    
    public CoralRenderer(EntityRendererManager manager)
    {
        super(manager, CORAL_MODEL, 0.5f);
        this.addLayer(new CoralFinLayer<>(this));
    }
    
    @Override
    public ResourceLocation getEntityTexture(CoralEntity coral)
    {
        return CORAL_TEXTURE;
    }
    
    @Override
    protected float handleRotationFloat(CoralEntity coral, float partialTicks)
    {
        return coral.getTailRotation();
    }
}

 

Layer-class:

package drachenbauer32.angrybirdsmod.entities.layers;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;

import drachenbauer32.angrybirdsmod.entities.models.CoralModel;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.IEntityRenderer;
import net.minecraft.client.renderer.entity.LivingRenderer;
import net.minecraft.client.renderer.entity.layers.LayerRenderer;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class CoralFinLayer<T extends LivingEntity> extends LayerRenderer<T, CoralModel<T>>
{
    private final EntityModel<T> coralModel = new CoralModel<>(true);
    
    public CoralFinLayer(IEntityRenderer<T, CoralModel<T>> coral)
    {
        super(coral);
    }
    
    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.isInvisible())
        {
            this.getEntityModel().copyModelAttributesTo(this.coralModel);
            this.coralModel.setLivingAnimations(entitylivingbaseIn, limbSwing, limbSwingAmount, partialTicks);
            this.coralModel.setRotationAngles(entitylivingbaseIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
            IVertexBuilder ivertexbuilder = bufferIn.getBuffer(RenderType.getEntityTranslucent(this.getEntityTexture(entitylivingbaseIn)));
            this.coralModel.render(matrixStackIn, ivertexbuilder, packedLightIn, LivingRenderer.getPackedOverlay(entitylivingbaseIn, 0.0F), 1.0F, 1.0F, 1.0F, 1.0F);
        }
    }
}

 

Model-class:

package drachenbauer32.angrybirdsmod.entities.models;

import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.entity.model.SegmentedModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class CoralModel<T extends Entity> extends SegmentedModel<T>
{
    private final ModelRenderer bone;
    private final ModelRenderer bone2;
    private final ModelRenderer bone3;
    private final ModelRenderer bone4;
    private final ModelRenderer bone5;
    private final ModelRenderer bone6;
    private final ModelRenderer bone7;
    
    public CoralModel(boolean layer)
    {
        textureWidth = 56;
        textureHeight = 32;
        
        bone = new ModelRenderer(this);
        bone.setRotationPoint(0.0F, 18.1F, 0.0F);
        
        bone2 = new ModelRenderer(this);
        bone3 = new ModelRenderer(this);
        bone4 = new ModelRenderer(this);
        bone5 = new ModelRenderer(this);
        bone6 = new ModelRenderer(this);
        bone7 = new ModelRenderer(this);
        
        if (layer)
        {
            bone.addBox("back_fin", 0.0F, -12.0F, 0.0F, 0, 12, 6, 0.0F, 38, 6);
        }
        else
        {
            bone.addBox("head", -4.0F, -8.0F, -4.0F, 8, 8, 8, 0.0F, 0, 0);
            bone.addBox("antenna_part_1", -0.5F, -12.0F, -4.0F, 1, 4, 1, 0.0F, 28, 0);
            bone.addBox("antenna_part_2", -0.5F, -12.0F, -6.0F, 1, 1, 2, 0.0F, 24, 5);
            bone.addBox("antenna_light", -1.0F, -12.0F, -8.0F, 2, 3, 2, 0.0F, 0, 0);
            
            bone2.setRotationPoint(0.0F, 20.1F, 0.0F);
            bone2.addBox("body", -3.0F, -4.0F, -3.0F, 6, 6, 6, 0.0F, 32, 0);
            
            bone3.setRotationPoint(-2.0F, 22.1F, -2.0F);
            bone3.addBox("right_front_leg", -1.0F, 0.0F, -1.0F, 2, 2, 2, 0.0F, 0, 16);
            bone3.addBox("right_front_flipper",  -1.0F, 2.0F, -2.0F, 2, 0, 1, 0.0F, 1, 20);
            
            bone4.setRotationPoint(2.0F, 22.1F, -2.0F);
            bone4.addBox("left_front_leg", -1.0F, 0.0F, -1.0F, 2, 2, 2, 0.0F, 8, 16);
            bone4.addBox("left_front_flipper",  -1.0F, 2.0F, -2.0F, 2, 0, 1, 0.0F, 9, 20);
            
            bone5.setRotationPoint(-2.0F, 22.1F, 2.0F);
            bone5.addBox("right_hind_leg", -1.0F, 0.0F, -1.0F, 2, 2, 2, 0.0F, 16, 16);
            bone5.addBox("right_hind_flipper",  -1.0F, 2.0F, -2.0F, 2, 0, 1, 0.0F, 17, 20);
            
            bone6.setRotationPoint(2.0F, 22.1F, 2.0F);
            bone6.addBox("left_hind_leg", -1.0F, 0.0F, -1.0F, 2, 2, 2, 0.0F, 24, 16);
            bone6.addBox("left_hind_flipper",  -1.0F, 2.0F, -2.0F, 2, 0, 1, 0.0F, 25, 20);
            
            bone7.setRotationPoint(0.0F, 20.1F, 3.0F);
            bone7.addBox("tail_part_1", -2.0F, -2.0F, 0.0F, 4, 4, 4, 0.0F, 0, 24);
            bone7.addBox("tail_part_2", -1.0F, 0.0F, 4.0F, 2, 2, 2, 0.0F, 4, 20);
            bone7.addBox("tail_fin",  0.0F, -1.0F, 6.0f, 0, 4, 2, 0.0F, 16, 26);
        }
    }
    
    @Override
    public Iterable<ModelRenderer> getParts()
    {
        return ImmutableList.of(bone, bone2, bone3, bone4, bone5, bone6, bone7);
    }
    
    @Override
    public void setRotationAngles(Entity coral, float limbSwing, float limbSwingAmount, float ageInTicks,
                                  float netHeadYaw, float headPitch)
    {
        bone.rotateAngleX = headPitch * 0.017453292f;
        bone.rotateAngleY = netHeadYaw * 0.017453292f;
        
        bone3.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 3 * limbSwingAmount;
        bone4.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 3 * limbSwingAmount;
        bone5.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 3 * limbSwingAmount;
        bone6.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 3 * limbSwingAmount;
        
        bone7.rotateAngleY = MathHelper.cos(limbSwing * 0.6662F) * 3 * limbSwingAmount;
        bone7.rotateAngleX = ageInTicks;
    }
}

I´m pretty sure, that it doesn´t matter, wich input-type i use in the constructor of the model to separate the maln-parts and the layer-part.

Link to comment
Share on other sites

Now i noticed, that i get no more error, if i remove the "<>" in the line, that has shown the error.

But it makes "rawtypes" and "unchecked" warnings.

So i wonder, why i cannot use the "<>"  like shown in the slime...

 

Now it renders the fin transparent, but stained glass blocks behind it appear invisible (in opposite order i can see the semi-transparent pixels of the fin throuch transparent blocks)...

 

2028462070_Coralingametransparentfin.png.acc7af917739982520c5991e98bc0481.png

You can see the ground and bodyparts of the entity through the fin, but not the edge of the glassblock at the top of the fin.

The scene is taken through another glassblock to show, that in the other order the transparencys work fine

 

How kan i make it able to show the transparencys in both directions correct?

 

Edited by Drachenbauer
Link to comment
Share on other sites

On 2/27/2020 at 10:41 PM, Drachenbauer said:

Now i noticed, that i get no more error, if i remove the "<>" in the line, that has shown the error.

But it makes "rawtypes" and "unchecked" warnings.

Learn Java basics: this was generics.

New in Modding? == Still learning!

Link to comment
Share on other sites

On 2/27/2020 at 10:02 PM, Drachenbauer said:

CoralModel<T extends Entity> extends SegmentedModel<T>

Your EntityModel need a Type (T was standing for Type, see Generics, and yes, the Characters you use are important, you can‘t use a character that dosen‘t match with Generics Char.), the Type that your Model class need was your entity or something else: i recommend you to remove the <T extends Entity> part and insert in the place of SemgentedModel<T> SemgentedModel<CoralEntity>, @Drachenbauer.

 

Then i am curious: How do you have make that your entity now have semi-transparent parts? Can you say it, this can help further people. And pls say it to your other topic: 

 

Edited by DragonITA

New in Modding? == Still learning!

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.