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

[1.18.1] InventoryScreen.renderEntityInInventory but only the head


 Share

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

Look at the constructor of CreeperModel. The model has child parts just like HumanoidModel, they are just set to private. You can use ModelPart#get or use an AccessTransformer to save the performance hit of looking up the part in a HashMap.

Link to comment
Share on other sites

  • 1 month later...
Posted (edited)

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

Ok actually, found the solution, for some reason there's no direct variable set for the body, instead I had to access it via:

((CreeperModel) model).root.getChild("body").visible = false;

Thanks for the help, finally resolved this :)

Link to comment
Share on other sites

Ok unfortunately it looks like held items and armour are still being rendered

For example, rendering a skeleton model with all but its head made invisible with the above code looks like this:


VLGyR1u.png

How can I also made these invisible?

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

You need generic parameters to refer to the type properly.

public static <T extends LivingEntity, M extends EntityModel<T>, R extends LivingEntityRenderer<T, M>> void doRendering(R renderer) {
    List<RenderLayer<T, M>> layers = renderer.layers;
    renderer.layers = List.of();
    // do rendering
    renderer.layers = layers;
}

 

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

    • Are you using Fabric? I'm not sure if this forum would be the right place then.
    • server failed to start and gives me "Failed to load data packs, can't proceed with server load. You can either fix your data packs or reset to vanilla with --safeMode" error when i look in my logs. its updated to the latest version of forge(40.1.0), and I don't have any data packs installed as far as I know. And I will upload the full logs if asked as i dont know how to attach a document to this post.  
    • Pioneer Craft [modded] {1.18.2} {SMP} {Community} {Light Roleplay} We are Pioneer Craft and we seek you !!! We are building a community of passionate players to build, trade, and share some laughs with. Are you tired of playing alone? Or are you here seeking a server with dedicated members; a server where you are not overlooked and can voice your opinions? If you are interested in these things too, then come join us in Pioneer Craft! Our server is player built and driven. We have a custom mod pack with mods chosen by our community to suit our needs. We have designed our server for player driven roleplay! There will be four communities which will each be self-sufficient. We encourage and seek builders who want to create a beautiful world to live in. This is a whitelist server and we are looking for dedicated applicants and experienced builders. Applications are located on our website which can be accessed through the discord. Other than the application questions, we are requesting photos of your prior builds which will be taken into consideration. Please show photos of your builds in the share-your-work section of the discord. The server uses CurseForge to run. This server is for mature members (16+) . Discord (must join): https://discord.gg/c4uJvb29CN
    • Pioneer Craft [modded] {1.18.2} {SMP} {Community} {Light Roleplay} We are Pioneer Craft and we seek you !!! We are building a community of passionate players to build, trade, and share some laughs with. Are you tired of playing alone? Or are you here seeking a server with dedicated members; a server where you are not overlooked and can voice your opinions? If you are interested in these things too, then come join us in Pioneer Craft! Our server is player built and driven. We have a custom mod pack with mods chosen by our community to suit our needs. We have designed our server for player driven roleplay! There will be four communities which will each be self-sufficient. We encourage and seek builders who want to create a beautiful world to live in. This is a whitelist server and we are looking for dedicated applicants and experienced builders. Applications are located on our website which can be accessed through the discord. Other than the application questions, we are requesting photos of your prior builds which will be taken into consideration. Please show photos of your builds in the share-your-work section of the discord. The server uses CurseForge to run. This server is for mature members (16+) . Discord (must join): https://discord.gg/c4uJvb29CN 
    • Update: I didn't need capabilities. In fact, I didn't need to override applyEffectTick at all. But it seems like I need reflections. The increased hitbox size now works for both entity and block collision--with a little drawback. This is what it looks like so far: // this event handler checks every tick if the living entity has the "big" effect @SubscribeEvent public static void entitySizeChange(LivingEvent.LivingUpdateEvent event) { LivingEntity livingEntity = event.getEntityLiving(); if (livingEntity.getActiveEffectsMap() != null && livingEntity.hasEffect(ModEffects.BIG.get())) { EntityDimensions newDims = livingEntity.getDimensions(livingEntity.getPose()).scale(8.0F, 2.0F); try { // using reflection Field field = Entity.class.getDeclaredField("dimensions"); field.setAccessible(true); field.set(livingEntity, newDims); // setting the living entity's EntityDimensions EntityDimensions newEntityDimensions = (EntityDimensions) field.get(livingEntity); livingEntity.setBoundingBox(newEntityDimensions.makeBoundingBox( // setting the living entity's AABB livingEntity.getX(), livingEntity.getY(), livingEntity.getZ() )); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } } }   The aforementioned drawback is that, when the effect wears off, the living entity's still keeps its bigger hitbox until it changes pose (i.e. my player crouching). Given that the EntityEvent.Size event fires whenever an entity changes pose, should I manually fire it with EVENT_BUS::post when that entity's effect wears off? If so, where? I tried manually firing EntityEvent.Size on my overridden removeAttributeModifiers(), but to no avail. 
  • Topics

×
×
  • Create New...

Important Information

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