Jump to content

getQuads in IBakedModel not being called


poopoodice

Recommended Posts

I feel it is more like a java related problem... anyways, here's my code:

public abstract class GunModel implements IBakedModel
{
    protected IBakedModel origin;
    public GunModel(IBakedModel origin)
    {
        this.origin = origin;
    }

    public abstract static class Overrides extends ItemOverrideList
    {
        public Overrides()
        {
            super();
        }

        @Nullable
        @Override
        public IBakedModel getModelWithOverrides(IBakedModel origin, ItemStack stack, @Nullable World world, @Nullable LivingEntity entity)
        {
            if (!(stack.getItem() instanceof AVAItemGun))
                return origin;
            CompoundNBT compound = ((AVAItemGun) stack.getItem()).initTags(stack);
            return getModel(origin, compound.getInt("fire"), compound.getInt("reload"), compound.getInt("run"));
        }

        protected abstract IBakedModel getModel(IBakedModel origin, int fire, int reload, int run);
    }
}

 

public class P226Model extends GunModel
{
    protected P226Overrides overrides;
    public P226Model(IBakedModel origin)
    {
        super(origin);
        overrides = new P226Overrides();
    }

    @Override
    public ItemOverrideList getOverrides()
    {
        return overrides;
    }

    public static class P226Overrides extends Overrides
    {
        public P226Overrides()
        {
            super();
        }

        @Override
        protected IBakedModel getModel(IBakedModel origin, int fire, int reload, int run)
        {
            return new ModifiedP226Model(origin, fire, reload, run);
        }
    }
}

 

public class ModifiedGunModel implements IBakedModel
{
    protected int fire;
    protected int reload;
    protected int run;
    protected IBakedModel origin;
    public ModifiedGunModel(IBakedModel origin, int fire, int reload, int run)
    {
        this.origin = origin;
        this.fire = fire;
        this.reload = reload;
        this.run = run;
    }

    @Override
    public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
    {
        System.out.println("parent");
        return origin.getQuads(state, side, rand);
    }

    @Override
    public ItemOverrideList getOverrides()
    {
        return null;
    }
}

 

public class ModifiedP226Model extends ModifiedGunModel
{
    public ModifiedP226Model(IBakedModel origin, int fire, int reload, int run)
    {
        super(origin, fire, reload, run);
    }

    @Override
    public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
    {
        System.out.println("inherited");
        return origin.getQuads(state, side, rand);
    }
  
    @Override
    public IBakedModel handlePerspective(ItemCameraTransforms.TransformType type, MatrixStack mat)
    {
        Vector3f rotation = null;
        Vector3f translation = null;
        Vector3f scale = null;
        switch (type)
        {
            case THIRD_PERSON_LEFT_HAND:
            case THIRD_PERSON_RIGHT_HAND:
                rotation = new Vector3f(70, 0, 0);
                translation = new Vector3f(0, 1, 3);
                scale = vector3f(1.65F);
                break;
            case FIRST_PERSON_LEFT_HAND:
            case FIRST_PERSON_RIGHT_HAND:
                rotation = new Vector3f(0, -23, 0);
                translation = new Vector3f(-2, 3.5F, 1.5F);
                scale = new Vector3f(1.5F, 1.5F, 1.5F);
                if (type == ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND)
                    this.modify(rotation, translation, scale, ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
                break;
            case GROUND:
                rotation = new Vector3f(0, 0, -90);
                break;
            case GUI:
                rotation = new Vector3f(0, -90, 0);
                translation = new Vector3f(-1, 1, 0);
                scale = vector3f(1.25F);
                break;
            case FIXED:
                rotation = new Vector3f(0, -90, 0);
                translation = new Vector3f(-1, 1.25F, 0);
                scale = vector3f(2);
                break;
        }
        this.getTransformationMatrix(rotation, translation, scale).push(mat);
        return this.origin.handlePerspective(type, mat);
    }
}

 

So what I'm struggling with is in

        @Override
        protected IBakedModel getModel(IBakedModel origin, int fire, int reload, int run)
        {
            return new ModifiedP226Model(origin, fire, reload, run);
        }

if I return a "ModifiedGunModel", it's getQuads() gets called. However if I return "ModifiedP226Model" which inherits from the "ModifiedGunModel", neither getQuads() gets called. Did I missed something or is this just not how it works?

Edited by poopoodice
Link to comment
Share on other sites

AFAIK, #handlePerspective returns the called model. So

public IBakedModel handlePerspective(ItemCameraTransforms.TransformType transform, MatrixStack stack) {
	// any code
	return original.handlePerspective(transform, stack); // will return `original`, which will bypass whatever custom model you have.
}

You'll have to replicate what #handlePerspective does to the model before it returns the same model. IIRC, it calls ForgeHooksClient.handlePerspective on the model, which actually does the transforming of the model.

  • Like 1
Link to comment
Share on other sites

10 minutes ago, sciwhiz12 said:

AFAIK, #handlePerspective returns the called model. So


public IBakedModel handlePerspective(ItemCameraTransforms.TransformType transform, MatrixStack stack) {
	// any code
	return original.handlePerspective(transform, stack); // will return `original`, which will bypass whatever custom model you have.
}

You'll have to replicate what #handlePerspective does to the model before it returns the same model. IIRC, it calls ForgeHooksClient.handlePerspective on the model, which actually does the transforming of the model.

Hi, I think you are right : )

it came out with if you return

this.origin.handlePerspective(type, mat)

somehow getQuads() will no longer gets called

On the other hand calls super works, or just do what I'm doing now:

        //some modification of rotationing scaling and translationing
	if (!transformationMatrix.isIdentity())
            transformationMatrix.push(mat);
        return getBakedModel();

 

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.