Jump to content

[solved] [1.15.2] How do i make the tail of my entity show it´s health like the wolf?


Recommended Posts

Posted (edited)

Hello

 

In the entity-class of the wolf, i founf a method for it´s tail to show it´s health.

    @OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
        if (this.isAngry())
        {
            return 1.5393804F;
        }
        else
        {
            return this.isTamed() ? (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F);
        }
    }

I reduced it to this for my own entity:

    @OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
         return this.isTamed() ?  (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F);
    }

Now, i want to remove the "isTamed"-part of the line, because i don´t work with taming theese entities.

But, if i try this, an error appears on the first position of Math.PI.

So i wonder, what "?" and ":" mean and how i can get rid of "isTamed" here...

Can you help?

 

Edit:

After alot of google i gound out, that "?" and ":" used together in such a case are another version of "if" and "else".

So i just hat to keep the part between them and remove the rest.

This is the result:

@OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
         return (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI;
    }

 

Edited by Drachenbauer
Posted
  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • 4 weeks later...
Posted (edited)

Now the tail of my entity is invisible (maybe it´s rotated into the body)

 

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 (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI;
    }
}

 

Renderer-class:

package drachenbauer32.angrybirdsmod.entities.renderers;

import drachenbauer32.angrybirdsmod.entities.CoralEntity;
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");
    
    public CoralRenderer(final EntityRendererManager manager)
    {
        super(manager, new CoralModel<>(), 0.625f);
    }
    
    @Override
    public ResourceLocation getEntityTexture(CoralEntity coral)
    {
        return CORAL_TEXTURE;
    }
    
    @Override
    protected float handleRotationFloat(CoralEntity coral, float partialTicks)
    {
        return coral.getTailRotation();
    }
    
    /*public static class RenderFactory implements IRenderFactory<CoralEntity>
    {
        @Override
        public EntityRenderer<? super CoralEntity> createRenderFor(EntityRendererManager manager)
        {
            return new CoralRenderer(manager);
        }
    }*/
}

 

Model-class

package drachenbauer32.angrybirdsmod.entities.models;

import com.google.common.collect.ImmutableList;
import drachenbauer32.angrybirdsmod.entities.CoralEntity;
import net.minecraft.client.renderer.entity.model.AgeableModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class CoralModel<T extends CoralEntity> extends AgeableModel<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()
    {
        textureWidth = 56;
        textureHeight = 32;
        
        bone = new ModelRenderer(this);
        bone.setRotationPoint(0.0F, 18.1F, 0.0F);
        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);
        bone.addBox("back_fin", 0.0F, -12.0F, 0.0F, 0, 12, 6, 0.0F, 38, 6);
        
        bone2 = new ModelRenderer(this);
        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 = new ModelRenderer(this);
        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 = new ModelRenderer(this);
        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 = new ModelRenderer(this);
        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 = new ModelRenderer(this);
        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 = new ModelRenderer(this);
        bone7.setRotationPoint(0.0F, 20.1F, 3.0F);
        bone7.addBox("tail_part_1", -2.0F, -2.0F, 0.0F, 4, 4, 4, 0.0F, 24, 16);
        bone7.addBox("tail_part_1", -1.0F, 0.0F, 4.0F, 2, 2, 2, 0.0F, 24, 16);
        bone7.addBox("tail_fin",  0.0F, -1.0F, 6.0f, 2, 0, 1, 0.0F, 25, 20);
    }
    
    @Override
    protected Iterable<ModelRenderer> getHeadParts()
    {
        return ImmutableList.of(bone);
    }
    
    @Override
    protected Iterable<ModelRenderer> getBodyParts()
    {
        return ImmutableList.of(bone2, bone3, bone4, bone5, bone6, bone7);
    }
    
    @Override
    public void setRotationAngles(CoralEntity coral, float limbSwing, float limbSwingAmount, float ageInTicks,
                                  float netHeadYaw, float headPitch)
    {
        bone.rotateAngleX = headPitch * 0.017453292f;
        bone.rotateAngleY = netHeadYaw * 0.017453292f;
        /*this.bone3.rotateAngleX = 0.5235988f + MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount;
        this.bone4.rotateAngleX = -0.5235988f + -(MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount);
        this.bone5.rotateAngleX = -0.5235988f + -(MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount);
        this.bone6.rotateAngleX = 0.5235988f + MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount;*/
        
        this.bone3.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;
        this.bone4.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
        this.bone5.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
        this.bone6.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;
        this.bone7.rotateAngleX = ageInTicks;
    }
}

bone7 is the tail,

bone3-bone6 are the legs, where i´m trying different limbswing calculations.

What´s wrong with the tail-movement?

Edited by Drachenbauer
Posted (edited)
On 1/26/2020 at 10:07 PM, Drachenbauer said:

Hello

 

In the entity-class of the wolf, i founf a method for it´s tail to show it´s health.


    @OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
        if (this.isAngry())
        {
            return 1.5393804F;
        }
        else
        {
            return this.isTamed() ? (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F);
        }
    }

I reduced it to this for my own entity:


    @OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
         return this.isTamed() ?  (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F);
    }

Now, i want to remove the "isTamed"-part of the line, because i don´t work with taming theese entities.

But, if i try this, an error appears on the first position of Math.PI.

So i wonder, what "?" and ":" mean and how i can get rid of "isTamed" here...

Can you help?

 

Edit:

After alot of google i gound out, that "?" and ":" used together in such a case are another version of "if" and "else".

So i just hat to keep the part between them and remove the rest.

This is the result:


@OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
         return (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI;
    }

 

Would help you, but i dont know what Object1 ? Object2 : Object3 was. Still searching but can you say the name?

 

On 2/21/2020 at 7:49 PM, Drachenbauer said:

 @Override public void setRotationAngles(CoralEntity coral, float limbSwing, float limbSwingAmount, float ageInTicks,  float netHeadYaw, float headPitch) { bone.rotateAngleX = headPitch * 0.017453292f; bone.rotateAngleY = netHeadYaw * 0.017453292f; /*this.bone3.rotateAngleX = 0.5235988f + MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount; this.bone4.rotateAngleX = -0.5235988f + -(MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount); this.bone5.rotateAngleX = -0.5235988f + -(MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount); this.bone6.rotateAngleX = 0.5235988f + MathHelper.cos(limbSwing * 5.0f) * 1.4f * limbSwingAmount;*/ this.bone3.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount; this.bone4.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; this.bone5.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount; this.bone6.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount; this.bone7.rotateAngleX = ageInTicks; }

Here you should rotate the Tail, it is the „Animation Function“.

Edited by DragonITA

New in Modding? == Still learning!

Posted

I still was a step further

It seams like now i have to change some of theese values to show the tail of my entity right:

return (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI;

In the basic model of my entity the tail points straight to the rear.

But i don´t know, where it points at the basic wolf-model...

Ingame it should point a bit upwart, if it has full health and a bit down, , if it´s damaged (angle by damage).

Posted (edited)
10 minutes ago, DragonITA said:

If heath was >= what you want then do something, in this case rotate the tail

Idon´t know what values exactly i have to calculate there for my entity.

 

There must be something different to the wolf with the tail´s basic angle.

other whise, it must show the same behavior as the wolf, if i use it´s code.

Edited by Drachenbauer
Posted (edited)
if(entity.getHealth == entity.getMaxHealth) {
	//rotate the tail
}else if(entity.getHealth >= 10.0F || entity.getHealth <= entity.getMaxHealth) {
  	//rotate the tail in a other angle
}

Am writing from mobile, dont know if the functions exactly are named so.

Edited by DragonITA

New in Modding? == Still learning!

Posted (edited)

I´, actually using this from the wolf:

return (0.55F - (this.getMaxHealth() - this.getHealth()) * 0.02F) * (float)Math.PI;

As i looked at my entity closer, i now think, the tail is not rendered...

But i do not know why...

Can you please look into my code a few posts above?

Maybe someone here finds the reason...

 

Edit:

i commented out this line in the Model-class for a test:

this.bone7.rotateAngleX = ageInTicks;

Then i noticed, that the textures of the tail where misplaced, and fixed this.

Then i activated the line again and saw the tail rotated upwards, slightly forwards.

90° defferent to a wolf´s tail.

 

Is the tail of the wolf rotated downwards in the basic model, before applying this effect?

 

how do i change the calculation at the top of this post by 90°?

 

Edit again:

With a little rotation-angle-test-model i found the value for 90°

Than i changed the line in the Model-class to:

bone7.rotateAngleX = ageInTicks - 1.5708F;

Now the tail is rotated right and i can use the rotation-calculation from the wolf sucessfully.

Edited by Drachenbauer
  • Like 1
Posted (edited)

Now i found another calculation, for creating the basic model with the tail straight horizontally to the rear.

And it doesn´t matter, what the max health is:

 

This in the Entity class, and the tail related things in the Renderer and Model-class exactly like used for the wolf:

    @OnlyIn(Dist.CLIENT)
    public float getTailRotation()
    {
        return -0.7854F + (this.getHealth() / this.getMaxHealth() * 1.0472F);
    }

 

the first float here is for 45° down and the second float is for a range of 60° With full health, the tail is 15° above horizontal and in the kill moment it´s 45° below horizontal.

 

@ DragonITA

Your variant has only a few angle steps for specific health value renges.

Mine in more smooth.

The tail-angle is changed a tiny little bit for each little bit of health, the entity looses.

And my code is shorter.

yours needs another "else if" -line for each angle-step.

Edited by Drachenbauer

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I've been having trouble trying to use forge as it shows a black screen when I open the game, but I can still interact with it and hear the music.  I've done all of the step by steps and most common fixes like updating drivers, keeping up to date with Java, deleting and reinstalling minecraft, restarting my computer MANY times, even smaller things like splash.properties (I didn't have that file so I added it and set it to false thinking it would do something, definitely not) and making sure to prioritize my rtx 3070 in the settings but with no luck. Minecraft works as intended when I uninstall forge and I also don't have any mods currently, it just gives me this issue when I install forge. I also increased the ram usage, made sure my hardware isn't full or anything, and even changed the resolution in hopes it would fix things. I checked my antivirus and firewall but that isn't the issue either. Trust me, I've done everything I can think of. For some reason the black screen does flicker a little into the main menu, but obviously unplayable. I couldn't even make my way to the settings with how little it flickered. I'm not sure if it flickered randomly or if it was because I was messing around moving and clicking a bunch, I didn't really test it that much.  
    • I've had a really weird issue recently,  I wanted to add the Depper and Darker mod on my dedicated server (MC 1.21 with Fabric 0.16.9, hosted on nitroserv.com) but whenever I do add the mod the sever stops doing anything after listing the mods, and I get no crash or error or anything, just a stuck server. Here's a normal log of the server booting up: https://pastebin.com/JipFF2Eh and here's the log of the server doing the weird thing: https://pastebin.com/W4JBh3eX I just don't understand it. I've tried removing other mods (somewhat randomly) but deeper and darker still breaks my server whenever I add it. NitroServ support staff is about as confused as I am and I've had no response from the Deeper and Darker support staff... Now I know this is the Forge support not the Fabric support but I'm just trying to know if anyone has any kind of idea to fix this (aside from not using the mod obviously) Also I still have a bunch of errors and warnings whenever the server does start properly, are there any of them I should be worried about?
    • Delete the config of RandomTweaker (config folder) If there is no change, remove this mod
    • Hello! So i have been trying to make a mod that adds plant fiber to minecraft 1.16.5 (i believe there are mods that add plant fiber but not for 1.16.5) but the problem is that i want to modify the loot table of grass to always drop plant fiber but also keep the vanilla drops. Most common answer i have seen is GlobalLootModifiers. But my tiny brain cant understand any tutorials. So any help is appreciated.
  • Topics

×
×
  • Create New...

Important Information

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