Jump to content

[1.18.1] InventoryScreen.renderEntityInInventory but only the head


SoLegendary

Recommended Posts

I want to be able to draw any humanoid mob or player in my custom screen but only the head of it, as opposed to the entire model.

I ideally would like to avoid having to create entirely new model resources just for this as I plan to be able to swap out any kind of humanoid mob/player skin easily.

I did see that net.minecraft.client.model.HumanoidModel.bodyParts() exists, but I want to exhaust other options before trying to modify existing entity model resources (which could potentially affect in-world rendering too, but I'm not sure).

Link to comment
Share on other sites

What I can roughly gather from renderEntityInInventory is its grabbing the model rendering data, applying gui-specific configs like disabling shadows and setting a constant rotation, rendering it and then resetting those configs. I don't really understand the matrix and quaternion math here though and I hope that it's not necessary to. I don't see anything inside of EntityRenderDispatcher or the LivingEntity that can directly modify model part visibilities though unless I'm missing something?

As for RenderPlayerEvent.Pre, do you mean the event itself has methods/data I need to adjust to control model visibilities or that this is simply the event to call my 'renderHead' function in once written?

Link to comment
Share on other sites

Ok cool so I managed to set visibility flags in RenderLivingEvent for any mob I need (note 'Unit' right now consists of Zombies, Skeletons and Creepers in my project):

    public static void onRenderLivingEntity(RenderLivingEvent.Pre<? extends LivingEntity, ? extends Model> evt) {
        LivingEntity entity = evt.getEntity();
        Model model = evt.getRenderer().getModel();

        if (entity instanceof Unit) {
            if (entity instanceof Creeper) {
                ((CreeperModel) model).root().visible = false;
            }
            else {
                ((HumanoidModel) model).body.visible = false;
            }
        }
    }

Skeletons and zombies work fine and I assume I can extend this to all humanoid mobs with maybe some small edge cases. However, the problem is creepers. They don't seem to have a head, instead only one ModelPart: 'root'. Setting this invisible makes the entire creeper invisible. Is there any way to actually separate the visibility of the creeper's head from the rest of the model?

Link to comment
Share on other sites

  • 1 month later...

Returning to this issue since I never actually solved it...

Seems that once the root ModelPart of any HierarchicalModel is set invisible, all of its child parts also are made invisible. Since the root of Creepers and spiders are also theirs torsos, this means I can't set the torso invisible without also making the head invisible.

Is there a way to separate the visibility of the root from its children?

EDIT: I've upped to 1.18.2 since I originally posted this

Edited by SoLegendary
version up
Link to comment
Share on other sites

Creepers only have the following parts:

   public final ModelPart root;
   public final ModelPart head;
   public final ModelPart rightHindLeg;
   public final ModelPart leftHindLeg;
   public final ModelPart rightFrontLeg;
   public final ModelPart leftFrontLeg;

Their torso section IS the root. This is what it looks like when I set everything except the head and root invisible:

GUjQQ9c.png

Link to comment
Share on other sites

What's the correct type for the variable that stores the layers (for the restoring step)?

I'm declaring it as:

List<RenderLayer<? extends LivingEntity, ? extends EntityModel<? extends LivingEntity>>> hudSelectedLayers = null;

I use the same type arguments for the LivingEntityRenderer itself and it seems to work fine, but not for the layers.

But when I try to assign LivingEntityRenderer.layers to it I get this error:

error: incompatible types: List<RenderLayer<CAP#1,CAP#2>> cannot be converted to List<RenderLayer<? extends Entity,? extends Model>>
            hudSelectedLayers = evt.getRenderer().layers;
                                                 ^
  where CAP#1,CAP#2 are fresh type-variables:
    CAP#1 extends LivingEntity from capture of ? extends LivingEntity
    CAP#2 extends EntityModel<CAP#1> from capture of ? extends Model

 

Link to comment
Share on other sites

  • 3 weeks later...

Sorry to resurrect this again, but I'm having issues specifically with IllagerModel, where for some reason setting the visibility of all the ModelParts except for the head and root does not result in the arms being made invisible:

XwOgDTZ.png

This is my code to set the visibility of all parts of a model except the head (so far only doing humanoids and hierarchicals, slowly extending to more mtypes):

    private void setNonHeadModelVisibility(Model model, boolean visibility) {

        if (model instanceof HumanoidModel) {
            ((HumanoidModel) model).hat.visible = visibility;
            ((HumanoidModel) model).body.visible = visibility;
            ((HumanoidModel) model).rightArm.visible = visibility;
            ((HumanoidModel) model).leftArm.visible = visibility;
            ((HumanoidModel) model).rightLeg.visible = visibility;
            ((HumanoidModel) model).leftLeg.visible = visibility;
        }
        else if (model instanceof HierarchicalModel) {

            ModelPart root = ((HierarchicalModel) model).root();
            ModelPart head = root.getChild("head");

            root.children.forEach((String name, ModelPart modelPart) -> {
                if (!modelPart.equals(head))
                    modelPart.visible = visibility;
            });
        }
    }

This code works so far for villagers, zombies, skeletons, creepers and spiders with no issue (and I'm sure many other mobs I've yet to check).

Thanks again for all the help with this feature so far!

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.