Drachenbauer Posted January 26, 2020 Posted January 26, 2020 (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 February 23, 2020 by Drachenbauer Quote
Cadiboo Posted January 27, 2020 Posted January 27, 2020 http://tutorials.jenkov.com/java/ternary-operator.html 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Drachenbauer Posted January 27, 2020 Author Posted January 27, 2020 Thanks, but as i edited the startpost, i already found something like that and separated the part of the line, that i needed. Quote
Drachenbauer Posted February 21, 2020 Author Posted February 21, 2020 (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 February 21, 2020 by Drachenbauer Quote
Drachenbauer Posted February 23, 2020 Author Posted February 23, 2020 I still don´t know, how to make the tail appear right. Quote
DragonITA Posted February 23, 2020 Posted February 23, 2020 (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 February 23, 2020 by DragonITA Quote New in Modding? == Still learning!
DragonITA Posted February 23, 2020 Posted February 23, 2020 (edited) If heath was >= what you want then do something, in this case rotate the tail Edited February 23, 2020 by DragonITA Quote New in Modding? == Still learning!
Drachenbauer Posted February 23, 2020 Author Posted February 23, 2020 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). Quote
Drachenbauer Posted February 23, 2020 Author Posted February 23, 2020 (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 February 23, 2020 by Drachenbauer Quote
DragonITA Posted February 23, 2020 Posted February 23, 2020 (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 February 23, 2020 by DragonITA Quote New in Modding? == Still learning!
Drachenbauer Posted February 23, 2020 Author Posted February 23, 2020 (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 February 24, 2020 by Drachenbauer 1 Quote
Drachenbauer Posted February 24, 2020 Author Posted February 24, 2020 (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 February 24, 2020 by Drachenbauer Quote
Recommended Posts
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.