Jump to content

Recommended Posts

Posted
package com.example.examplemod.entity.renderer
import com.example.examplemod.ExampleMod;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.HumanoidMobRenderer;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
import net.minecraft.resources.ResourceLocation;
  
  
  public class ExampleEntityRenderer<Type extends ExampleEntity> extends HumanoidMobRenderer<Type, ExampleEntityModel<Type>> {
    private static final ResourceLocation TEXTURE = new ResourceLocation(ExampleMod.MOD_ID,
        "textures/entity/example/exampleentity.png");

public ExampleEntityRenderer(EntityRendererProvider.Context context) {
        super(context, new ExampleEntityModel<>(context.bakeLayer(ExampleEntityModel.LAYER_LOCATION)), 0.6f);
        this.addLayer(new ItemInHandLayer<>(this));
        this.addLayer(new HumanoidArmorLayer<>(this,
                new HumanoidModel(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)),
                new HumanoidModel(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR))));
}

@Override
public ResourceLocation getTextureLocation(Type entity) {
        return TEXTURE;
        }
}

If your entity model extends the humanoid model and has the appropriate methods and items in its equipment slots, it will hopefully render them

Posted

Ignoring the mismatched format, this doesn't really explain anything about what is needed. First, you have a bunch of random classes which you don't define: ExampleEntityModel, the layer location, model layers, etc. Even if they are not relevant, you should just hide them behind a `//...` so they don't detract from your main point. For example, what about registering the layer definitions? the entity renderer? Anything that is not explained should be mentioned to use the same method as usual. You should also explain why adding those two layers would do what you needed. Additionally, you need to explain when a different model layer should be used, since not all mobs will have the exact same dimensions as the player (e.g., piglin). 

2 hours ago, EaSports69 said:
package com.example.examplemod.entity.renderer

This will crash, it needs a semicolon.

2 hours ago, EaSports69 said:
        this.addLayer(new ItemInHandLayer<>(this));

This is already added for HumanoidMobRenderer, so it is redundant.

2 hours ago, EaSports69 said:
this.addLayer(new HumanoidArmorLayer<>(this,
                new HumanoidModel(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)),
                new HumanoidModel(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR))));

This will crash, you need to pass in a ModelManager from the context. Additionally, the type parameter for HumanoidModel should be inferred and not just removed.

 

Posted (edited)

I use the exampleentity model as it's basically, an example. also in order for it to work(sorry for not clarifying again), you need to add in your Entity class

 the

    protected void populateDefaultEquipmentSlots(DifficultyInstance difficultyInstance) {
        super.populateDefaultEquipmentSlots(difficultyInstance);
        this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.DIAMOND_SWORD.get()));
        this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(Items.DIAMOND_HELMET.get()));
        this.setItemSlot(EquipmentSlot.CHEST, new ItemStack(Items.DIAMOND_CHESTPLATE.get()));
        this.setItemSlot(EquipmentSlot.LEGS, new ItemStack(Items.DIAMOND_LEGGINGS.get()));
        this.setItemSlot(EquipmentSlot.FEET, new ItemStack(Items.DIAMOND_BOOTS.get()));
    }

//This adds the items in your entity's respective slots, here I'm using for an example diamond items

 In your model, you need to extend the HumanoidModel class, and it should look like this

 

public class PigmanEntityModel<Type extends ExampleEntity> extends HumanoidModel<Type> {
	// This extends the humanoid model in your class and makes possible the animations and the ability to hold items
	public static final ModelLayerLocation LAYER_LOCATION =
			new ModelLayerLocation(new ResourceLocation(ExampleMod.MOD_ID, "example"), "main");

	public ExampleEntityModel(ModelPart modelPart) {
		super(modelPart);

	}

	public static LayerDefinition createBodyLayer() {
		MeshDefinition meshdefinition = new MeshDefinition();
		PartDefinition partdefinition = meshdefinition.getRoot();

		PartDefinition head = partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition hat = partdefinition.addOrReplaceChild("hat", CubeListBuilder.create().texOffs(32, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F).extend(0.5F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition right_arm = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(-5.0F, 2.0F, 0.0F));
		PartDefinition left_arm = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).mirror().addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(5.0F, 2.0F, 0.0F));
		PartDefinition right_leg = partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(-1.9F, 12.0F, 0.0F));
		PartDefinition left_leg = partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(16, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(1.9F, 12.0F, 0.0F));
//This is if you use the player model only
		return LayerDefinition.create(meshdefinition, 64, 64);
	}

	public void prepareMobModel(Type p_103793_, float p_103794_, float p_103795_, float p_103796_) {
		this.rightArmPose = HumanoidModel.ArmPose.EMPTY;
		this.leftArmPose = HumanoidModel.ArmPose.EMPTY;
		ItemStack itemstack = p_103793_.getItemInHand(InteractionHand.MAIN_HAND);
		if (itemstack.is(Items.CROSSBOW) && p_103793_.isAggressive()) {
			if (p_103793_.getMainArm() == HumanoidArm.RIGHT) {
				this.rightArmPose = ArmPose.ITEM;
			} else {
				this.leftArmPose = ArmPose.ITEM;
			}
		}
//This adds the arm poses and the attack animations if the mob is hostile
		super.prepareMobModel(p_103793_, p_103794_, p_103795_, p_103796_);
	}
	public void setupAnim(Type p_103798_, float p_103799_, float p_103800_, float p_103801_, float p_103802_, float p_103803_) {
		super.setupAnim(p_103798_, p_103799_, p_103800_, p_103801_, p_103802_, p_103803_);
		ItemStack itemstack = p_103798_.getMainHandItem();
		if (p_103798_.isAggressive() && (itemstack.isEmpty() || !itemstack.is(Items.DIAMOND_SWORD))) {
			float f = Mth.sin(this.attackTime * (float)Math.PI);
			float f1 = Mth.sin((1.0F - (1.0F - this.attackTime) * (1.0F - this.attackTime)) * (float)Math.PI);
			this.rightArm.zRot = 0.0F;
			this.leftArm.zRot = 0.0F;
			this.rightArm.yRot = -(0.1F - f * 0.6F);
			this.leftArm.yRot = 0.1F - f * 0.6F;
			this.rightArm.xRot = (-(float)Math.PI / 2F);
			this.leftArm.xRot = (-(float)Math.PI / 2F);
			this.rightArm.xRot -= f * 1.2F - f1 * 0.4F;
			this.leftArm.xRot -= f * 1.2F - f1 * 0.4F;
			AnimationUtils.bobArms(this.rightArm, this.leftArm, p_103801_);
		}
//This adds the basic animations for the mob and the attack animations
	}
	public void translateToHand(HumanoidArm p_103778_, PoseStack p_103779_) {
		float f = p_103778_ == HumanoidArm.RIGHT ? 1.0F : -1.0F;
		ModelPart modelpart = this.getArm(p_103778_);
		modelpart.x += f;
		modelpart.translateAndRotate(p_103779_);
		modelpart.x -= f;
      //This is for the arm
	}

After importing the necessary classes it should work(Keep in mind this is for 1.18.2)

Edited by EaSports69
Didn't clarify

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Also add the latest.log from /logs/
    • I was hoping I could get some help with this weird crash. I've hosted many servers before and never had this issue. Now and then the server crashed with "Exception ticking world". Everywhere I looked I rarely found any info on it (usually found ticking entity instead). Any advice I did get (mostly from the modpack owner's discord) was "We don't know and it's near impossible to find out what it is". Here is the crash report:   Description: Exception ticking world java.util.ConcurrentModificationException     at java.util.HashMap$HashIterator.nextNode(Unknown Source)     at java.util.HashMap$KeyIterator.next(Unknown Source)     at net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:386)     at net.minecraft.server.management.PlayerChunkMapEntry.sendToPlayers(PlayerChunkMapEntry.java:162)     at net.minecraft.server.management.PlayerChunkMap.tick(SourceFile:165)     at net.minecraft.world.WorldServer.tick(WorldServer.java:227)     at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:756)     at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:397)     at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:668)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source)   If you want the full version, I can link a pastebin if needed. Modpack link: https://www.curseforge.com/minecraft/modpacks/multiblock-madness Some helpful information is that: It seems to only happen when I leave my void world to enter the overworld. Only happens 5-10% of the time. Only happens when leaving the void world, and only the void world. I know it's a slim chance someone could help, but it'd be greatly appreciated.
    • thanks a lot bro i knew i shouldve gone on the actual website instead of the discord
    • Minecraft Version? Reinstall Java 17 and/or Java 21 If this is still not working, run jarfix https://johann.loefflmann.net/de/software/jarfix/index.html
    • Hallo liebes Forge team, mein forge installer nimmt nicht die Java datei an bzw. zeigt nicht das Symbol und öffnet immer nur kurz die console und schließt sich dann wieder.  Ich habe die neueste java datei und die neueste forge datei und es öffnet trotzdem nichts.  Könntet ihr mir dabei weiterhelfen?
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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