Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


Drachenbauer
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • 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)

Link to comment
Share on other sites

  • 4 weeks later...

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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.

Guest
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hey! I keep getting this error when I start my own Minecraft server: (Also to note: I am not very knowledge on how Java works as my servers have almost never had any type of issue) 2021-10-23 18:47:36,993 main ERROR Error processing element Queue ([Appenders: null]): CLASS_NOT_FOUND 2021-10-23 18:47:37,041 main WARN Advanced terminal features are not available in this environment 2021-10-23 18:47:37,078 main ERROR Unable to locate appender "ServerGuiConsole" for logger config "root" ←[32m[18:47:37] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 31.2.50, --fml.mcpVersion, 20200515.085601, --fml.mcVersion, 1.15.2, --fml.forgeGroup, net.minecraftforge, nogui] ←[m←[32m[18:47:37] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 5.1.2+70+master.2845bb9 starting: java version 15.0.2 by Oracle Corporation ←[m←[1;31m[18:47:37] [main/FATAL] [ne.mi.fm.lo.FMLLoader/CORE]: Access Transformer library is missing, we need this to run ←[m←[1;31m[18:47:37] [main/ERROR] [cp.mo.mo.TransformationServiceDecorator/MODLAUNCHER]: Service failed to load fml cpw.mods.modlauncher.api.IncompatibleEnvironmentException: Missing AccessTransformer, cannot run         at net.minecraftforge.fml.loading.FMLLoader.lambda$onInitialLoad$1(FMLLoader.java:104) ~[forge2.jar:31.2] {}         at java.util.Optional.orElseThrow(Optional.java:401) ~[?:?] {}         at net.minecraftforge.fml.loading.FMLLoader.onInitialLoad(FMLLoader.java:102) ~[forge2.jar:31.2] {}         at net.minecraftforge.fml.loading.FMLServiceProvider.onLoad(FMLServiceProvider.java:122) ~[forge2.jar:31.2] {}         at cpw.mods.modlauncher.TransformationServiceDecorator.onLoad(TransformationServiceDecorator.java:53) ~[modlauncher-5.1.2.jar:?] {}         at cpw.mods.modlauncher.TransformationServicesHandler.lambda$loadTransformationServices$11(TransformationServicesHandler.java:131) ~[modlauncher-5.1.2.jar:?] {}         at java.util.HashMap$Values.forEach(HashMap.java:1067) [?:?] {}         at cpw.mods.modlauncher.TransformationServicesHandler.loadTransformationServices(TransformationServicesHandler.java:131) [modlauncher-5.1.2.jar:?] {}         at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:56) [modlauncher-5.1.2.jar:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:75) [modlauncher-5.1.2.jar:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.1.2.jar:?] {}         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) [forge2.jar:?] {}         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) [forge2.jar:?] {}         at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) [forge2.jar:?] {} ←[m←[1;31m[18:47:37] [main/ERROR] [cp.mo.mo.TransformationServicesHandler/MODLAUNCHER]: Found 1 services that failed to load : [fml] ←[m←[32m[18:47:37] [main/INFO] [STDERR/]: [net.minecraftforge.server.ServerMain$Runner:runLauncher:65]: The server is missing critical libraries and cannot load. Please run the installer to correct this ←[m
    • Hi, I don't know much about Minecraft Mod programming, and I'm making a mod, I need to know how to scale the model from the adult version to the child version. I'm currently doing the mod itself by Mcreator, and modeling by Blockbench. The reproduction of this mob is done, the problem is, the child is the same size as the adult. At first I would use two different models for this animal, but researching a little, I found that there is a way to scale the model. I wanted to know how to do this. Here below is the code.  
    • When I try to load it. It starts up but none can join the server as the forge jar is corrupted some how. Believe it is a fault in the update.  
    • Sorry I didn’t explain it in much detail at first hopefully this will be much more easier to understand. I am running a 1.16.5 forge server with java 8 there is multiple errors which you can see in the paste bin right at the top. Not sure what is the problem with it I followed a YouTube video it worked for him but not for me I believe it is because it is not registering the main class which is coursing the forge not to work it has no mods at all.
    • Here is the Link to the debug.log.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.