Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I have this problem where one entity would play the animation fine on land (like it's supposed to) and when i add another similar entity whereas it is not on land (not supposed to play animation) will not play animation until the first entity renders on screen. 

In which it will follow the same exact animation as the one on land until the first entity goes off screen.

 

Any help would be greatly appreciated. Feel free to clarify if my explanation isn't understandable

 

Model Code

Spoiler

import com.google.common.collect.ImmutableList;
import com.hoopawolf.mwaw.entities.SandWyrmEntity;
import com.sun.javafx.geom.Vec3f;
import net.minecraft.client.renderer.entity.model.SegmentedModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.ArrayList;

@OnlyIn(Dist.CLIENT)
public class SandWyrmModel<T extends SandWyrmEntity> extends SegmentedModel<T>
{
    private final ModelRenderer Head;
    private final ModelRenderer Mouth;
    private final ModelRenderer TuskRight;
    private final ModelRenderer TuskLeft;
    private final ModelRenderer Body1;
    private final ModelRenderer Body2;
    private final ModelRenderer Tail1;
    private final ModelRenderer Tail2;
    private final ModelRenderer Tail3;
    private final ModelRenderer EndTail;
    private final ModelRenderer LeftFrontLeg;
    private final ModelRenderer LeftBackLeg;
    private final ModelRenderer RightFrontLeg;
    private final ModelRenderer RightBackLeg;

    private ArrayList<ModelRenderer> modelParts = new ArrayList<ModelRenderer>();
    private final ImmutableList<ModelRenderer> immutableList;
    Vec3f lastPos = new Vec3f();
    Vec3f newPos = new Vec3f();

    public SandWyrmModel()
    {
        textureWidth = 123;
        textureHeight = 121;

        Head = new ModelRenderer(this);
        Head.setRotationPoint(0.0F, 14.0F, -20.0F);
        Head.addBox("Head", -7.0F, -3.0F, -9.0F, 14, 9, 5, 0.0F, 73, 91);
        Head.addBox("Head", -9.0F, -6.0F, -21.0F, 18, 5, 21, 0.0F, 0, 58);

        Mouth = new ModelRenderer(this);
        Mouth.setRotationPoint(0.0F, 4.0F, -7.0F);
        Mouth.rotateAngleX = -0.2618F;
        Mouth.rotateAngleY = 0.0F;
        Mouth.rotateAngleZ = 0.0F;
        Head.addChild(Mouth);
        Mouth.addBox("Mouth", -6.0F, -1.1603F, -12.5484F, 12, 3, 12, 0.0F, 0, 84);

        TuskRight = new ModelRenderer(this);
        TuskRight.setRotationPoint(7.0F, 1.0F, 9.0F);
        Head.addChild(TuskRight);
        TuskRight.addBox("TuskRight", -15.0F, -2.0F, -32.0F, 2, 4, 17, 0.0F, 31, 84);

        TuskLeft = new ModelRenderer(this);
        TuskLeft.setRotationPoint(-7.0F, 1.0F, 8.0F);
        Head.addChild(TuskLeft);
        TuskLeft.addBox("TuskLeft", 13.0F, -2.0F, -31.0F, 2, 4, 17, 0.0F, 52, 91);

        Body1 = new ModelRenderer(this);
        Body1.setRotationPoint(0.0F, 14.0F, -20.0F);
        Body1.addBox("Body1", -12.0F, -4.0F, -4.0F, 24, 11, 19, 0.0F, 0, 0);
        modelParts.add(Body1);

        LeftFrontLeg = new ModelRenderer(this);
        LeftFrontLeg.setRotationPoint(14.0F, 1.0F, -0.5F);
        Body1.addChild(LeftFrontLeg);
        LeftFrontLeg.addBox("LeftFrontLeg", -2.0F, -1.0F, -2.5F, 5, 10, 7, 0.0F, 0, 99);

        RightFrontLeg = new ModelRenderer(this);
        RightFrontLeg.setRotationPoint(-14.0F, 1.0F, -0.5F);
        Body1.addChild(RightFrontLeg);
        RightFrontLeg.addBox("RightFrontLeg", -3.0F, -1.0F, -2.5F, 5, 10, 7, 0.0F, 0, 99);

        Body2 = new ModelRenderer(this);
        Body2.setRotationPoint(0.0F, 2.0F, 13.0F);
        Body1.addChild(Body2);
        Body2.addBox("Body2", -11.0F, -5.0F, 2.0F, 22, 10, 18, 0.0F, 0, 30);
        modelParts.add(Body2);

        LeftBackLeg = new ModelRenderer(this);
        LeftBackLeg.setRotationPoint(-11.0F, 2.0F, -41.5F);
        Body2.addChild(LeftBackLeg);
        LeftBackLeg.addBox("LeftBackLeg", 22.0F, -1.0F, 53.5F, 5, 7, 7, 0.0F, 24, 105);

        RightBackLeg = new ModelRenderer(this);
        RightBackLeg.setRotationPoint(11.0F, 2.0F, -41.5F);
        Body2.addChild(RightBackLeg);
        RightBackLeg.addBox("RightBackLeg", -27.0F, -1.0F, 53.5F, 5, 7, 7, 0.0F, 24, 105);

        Tail1 = new ModelRenderer(this);
        Tail1.setRotationPoint(0.0F, 0.0F, 18.0F);
        Body2.addChild(Tail1);
        Tail1.addBox("Tail1", -9.0F, -4.0F, 2.0F, 18, 8, 9, 0.0F, 67, 0);
        modelParts.add(Tail1);

        Tail2 = new ModelRenderer(this);
        Tail2.setRotationPoint(0.0F, 0.0F, 9.0F);
        Tail1.addChild(Tail2);
        Tail2.addBox("Tail2", -9.0F, -4.0F, 2.0F, 18, 7, 10, 0.0F, 57, 58);
        modelParts.add(Tail2);

        Tail3 = new ModelRenderer(this);
        Tail3.setRotationPoint(0.0F, 0.0F, 10.0F);
        Tail2.addChild(Tail3);
        Tail3.addBox("Tail3", -8.0F, -4.0F, 2.0F, 16, 6, 10, 0.0F, 68, 75);
        modelParts.add(Tail3);

        EndTail = new ModelRenderer(this);
        EndTail.setRotationPoint(0.0F, 0.0F, 9.0F);
        Tail3.addChild(EndTail);
        EndTail.addBox("EndTail", -14.0F, -1.0F, -1.0F, 28, 0, 16, 0.0F, 46, 30);
        modelParts.add(EndTail);

        ImmutableList.Builder<ModelRenderer> builder = ImmutableList.builder();
        builder.add(this.Head);
        builder.add(this.Body1);
        this.immutableList = builder.build();
    }

    @Override
    public Iterable<ModelRenderer> getParts()
    {
        return immutableList;
    }

    public void setRotationAngles(SandWyrmEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch)
    {
        Head.rotateAngleY = netHeadYaw * ((float) Math.PI / 270F);
        Head.rotateAngleX = headPitch * ((float) Math.PI / 270F);

        if (entityIn.onGround)
        {
            for (int i = 0; i < this.modelParts.size(); ++i)
            {
                if (i == 0)
                {
                    lastPos.set(this.modelParts.get(i).rotateAngleX, this.modelParts.get(i).rotateAngleY, this.modelParts.get(i).rotateAngleZ);
                    this.modelParts.get(i).rotateAngleX = MathHelper.cos(ageInTicks * 0.4F) * (float) Math.PI * 0.02F * (float) (1 + Math.abs(i - 2));
                    this.modelParts.get(i).rotateAngleY = 0.0F;
                    this.modelParts.get(i).rotateAngleZ = 0.0F;
                } else
                {
                    newPos.set(lastPos.x, lastPos.y, lastPos.z);
                    lastPos.set(this.modelParts.get(i).rotateAngleX, this.modelParts.get(i).rotateAngleY, this.modelParts.get(i).rotateAngleZ);

                    this.modelParts.get(i).rotateAngleX = newPos.x;
                    this.modelParts.get(i).rotateAngleY = newPos.y;
                    this.modelParts.get(i).rotateAngleZ = newPos.z;
                }
            }
        }
    }
}

 

Render Code

Spoiler

import com.hoopawolf.mwaw.entities.SandWyrmEntity;
import com.hoopawolf.mwaw.entities.model.SandWyrmModel;
import com.hoopawolf.mwaw.ref.Reference;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class SandWyrmRenderer extends MobRenderer<SandWyrmEntity, SandWyrmModel<SandWyrmEntity>>
{
    private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/entity/sandwyrm.png");

    public SandWyrmRenderer(EntityRendererManager _manager)
    {
        super(_manager, new SandWyrmModel<>(), 1.0f);
    }

    @Override
    public ResourceLocation getEntityTexture(SandWyrmEntity _entity)
    {
        return TEXTURE;
    }
}

 

 

Client Proxy (if needed)

Spoiler


import com.hoopawolf.mwaw.entities.renderer.FairyRenderer;
import com.hoopawolf.mwaw.entities.renderer.SandWyrmRenderer;
import com.hoopawolf.mwaw.ref.Reference;
import com.hoopawolf.mwaw.util.RegistryHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;


@Mod.EventBusSubscriber(modid = Reference.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ClientProxy implements IProxy
{
    @Override
    public World getClientWorld()
    {
        return Minecraft.getInstance().world;
    }

    @Override
    public PlayerEntity getClientPlayer()
    {
        return Minecraft.getInstance().player;
    }

    @SubscribeEvent
    public static void onClientSetUp(final FMLClientSetupEvent event)
    {
        RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.FAIRY_ENTITY.get(), FairyRenderer::new);
        RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.SAND_WYRM_ENTITY.get(), SandWyrmRenderer::new);
    }
}

 

 

You need an else statement in the setRotationAngles method to reset the angles back to default if the entity isn't on the ground as it is using the rotation angles for the one that is on the ground. There is only one Model object which is used globally for all entities so the rotation angles are being shared and only updated on the one which is grounded.

  • Author

@CHEESEBOT314 Thanks for the reply!

I've already tried that and it messed with the entity that is on ground's animation. Is there another way or do I have to find another method to do it?

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.