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

  On 6/2/2023 at 10:59 AM, EaSports69 said:
package com.example.examplemod.entity.renderer
Expand  

This will crash, it needs a semicolon.

  On 6/2/2023 at 10:59 AM, EaSports69 said:
        this.addLayer(new ItemInHandLayer<>(this));
Expand  

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

  On 6/2/2023 at 10:59 AM, EaSports69 said:
this.addLayer(new HumanoidArmorLayer<>(this,
                new HumanoidModel(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)),
                new HumanoidModel(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR))));
Expand  

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

    • Try other builds of this modpack or report it to the modpack creator Looks like an issue with environmental, naturalist and/or crafttweaker
    • Hello! There is an issue with my world(Chocolate Edition modpack), after joining the world all creatures are frozen and the game is not responding or the game crashes after short period of time. Reproduction Steps: Turn on the game Join the world Game crashes immediately or after short period of time. Additional info: Crash log saying that an entity crashed the game is created after the crash(not the logs that I posted, different file from crash-logs, game crashed 3x by Snail, 1x by Small Snail, 1x by Tortoise) Specification: CPU: i5-13600KF GPU: GTX 1070 RAM: 32GB 3200MhZ - allocated 10GB Log links: latest.log: https://mclo.gs/Lp8zlsv crash-reports/crash: https://mclo.gs/XhtyJQI Minecraft version: 1.19.2 Modpack Version: Chocolate Edition 1.9 OS: Windows 10 Java Version: 22.0.2 Minecraft Java: Java 17
    • Hello, for several days I've been trying to find a way to add my animations in this style. @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { }   My current public class is : public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<EntityRenderState>   But i can't do that :  public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<T> Type parameter 'T' is not within its bound; should extend 'net.minecraft.client.renderer.entity.state.EntityRenderState' But with EntityRenderState it ok and it work !   But my setupAnim look like this :  @Override public void setupAnim(EntityRenderState p_370046_) { super.setupAnim(p_370046_); }   I don't have any access to my entity ! Look like 1.21.1 : @Override public void setupAnim(FakePlayerEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch); this.animateWalk(FakePlayerEntityAnimations.ANIM_PLAYERS_WALKING, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(entity.idleAnimationState, FakePlayerEntityAnimations.ANIM_PLAYERS_IDLE, ageInTicks, 1f); } But i'm stuck with new version of Forge...
    • Looks like an issue with abyssalsovereigns - this mod has functions that are not working on a server (client-side-only mod)
    • I added some new mods and updated old ones to my forge server and they will run successfully but the moment I try to join ill briefly load into the world and get booted with the message, internal server error. The mods in question work fine on singleplayer and removing too many from the server causes it to stop working so I cant be sure which one is causing the problem... any ideas? server log: https://pastebin.com/hGH8UUjm client log (from modrinth app): https://mclo.gs/a3oOUGY
  • Topics

×
×
  • Create New...

Important Information

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