Jump to content

Items do not equip correctly in the hand of my custom Entity/Mob.


CrawKatt

Recommended Posts

Hi, I'm a newbie in Minecraft Mods and I've been following some guides to create my Mod. But I've had a problem that I have not been able to solve in any way. When I try to equip an item to my custom Entity like for example, a diamond sword, The item never renders in your hand.

file-81z9Uo3JVQsy6q5jAZf7ve0k.png?ex=668

How can I solve this? I leave the code of my entity below
 

BrotecitoModel class

package com.example.examplemod.entity.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.ArmedModel;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.HumanoidArm;

public class BrotecitoModel<T extends Entity> extends HierarchicalModel<T> implements ArmedModel {
	private final ModelPart brotecito;
	private final ModelPart arms;
	private final ModelPart pot;
	private final ModelPart rightArm;
	private final ModelPart leaf;
	private final ModelPart head;
	private final ModelPart leftArm;
	private final ModelPart frontPot;
	private final ModelPart backPot;
	private final ModelPart leftPot;
	private final ModelPart rightPot;
	private final ModelPart upperLeftPot;
	private final ModelPart upperRightPot;
	private final ModelPart upperFrontPot;
	private final ModelPart upperBackPot;
	private final ModelPart bottomPotFaceAndSoil;

	public BrotecitoModel(ModelPart root) {
		this.brotecito = root.getChild("brotecito");
		this.leaf = brotecito.getChild("leaf");
		this.head = brotecito.getChild("head");
		this.arms = brotecito.getChild("arms");
		this.pot = brotecito.getChild("pot");

		this.leftArm = arms.getChild("leftArm");
		this.rightArm = arms.getChild("rightArm");

		this.frontPot = pot.getChild("frontPot");
		this.backPot = pot.getChild("backPot");
		this.leftPot = pot.getChild("leftPot");
		this.rightPot = pot.getChild("rightPot");
		this.upperLeftPot = pot.getChild("upperLeftPot");
		this.upperRightPot = pot.getChild("upperRightPot");
		this.upperFrontPot = pot.getChild("upperFrontPot");
		this.upperBackPot = pot.getChild("upperBackPot");
		this.bottomPotFaceAndSoil = pot.getChild("bottomPotFaceAndSoil");
	}

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

		PartDefinition brotecito = partdefinition.addOrReplaceChild("brotecito", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));
		PartDefinition leaf = brotecito.addOrReplaceChild("leaf", CubeListBuilder.create().texOffs(1, 4).addBox(1.3045F, 1.7638F, 2.1262F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(1.3045F, -13.7638F, 4.1262F, -3.1416F, 0.0F, 3.1416F));
		PartDefinition leafLower_r1 = leaf.addOrReplaceChild("leafLower_r1", CubeListBuilder.create().texOffs(53, 44).addBox(-2.3827F, -0.2609F, 1.5675F, 3.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
				.texOffs(53, 41).addBox(-2.3827F, -7.2609F, 1.5675F, 3.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
				.texOffs(51, 18).addBox(-3.3827F, -6.2609F, 1.5675F, 5.0F, 6.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.3394F, 2.5155F, -1.0048F, 0.7854F, 0.3927F, 0.0F));
		PartDefinition leaftRoot2_r1 = leaf.addOrReplaceChild("leaftRoot2_r1", CubeListBuilder.create().texOffs(1, 1).addBox(-0.8827F, -1.9942F, 1.1189F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.5926F, 3.4932F, 0.7139F, 0.3927F, 0.3927F, 0.0F));
		PartDefinition head = brotecito.addOrReplaceChild("head", CubeListBuilder.create().texOffs(41, 1).addBox(-4.9286F, -2.3571F, 4.5F, 10.0F, 6.0F, 1.0F, new CubeDeformation(0.0F))
				.texOffs(26, 28).addBox(-4.9286F, -3.3571F, -4.5F, 10.0F, 1.0F, 9.0F, new CubeDeformation(0.0F))
				.texOffs(27, 19).addBox(-3.9286F, -4.3571F, -3.5F, 8.0F, 1.0F, 7.0F, new CubeDeformation(0.0F))
				.texOffs(1, 8).addBox(-3.9286F, 3.6429F, -4.5F, 8.0F, 1.0F, 9.0F, new CubeDeformation(0.0F))
				.texOffs(1, 35).addBox(-5.9286F, -2.3571F, -4.5F, 2.0F, 6.0F, 9.0F, new CubeDeformation(0.0F))
				.texOffs(10, 19).addBox(3.0714F, -2.3571F, -4.5F, 3.0F, 6.0F, 9.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0714F, -6.6429F, -0.5F, -3.1416F, 0.0F, 3.1416F));
		PartDefinition backFace_r1 = head.addOrReplaceChild("backFace_r1", CubeListBuilder.create().texOffs(28, 0).addBox(4.0F, -8.0F, -5.0F, 1.0F, 6.0F, 10.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0714F, 5.6429F, -0.5F, 0.0F, 1.5708F, 0.0F));
		PartDefinition arms = brotecito.addOrReplaceChild("arms", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition rightArm = arms.addOrReplaceChild("rightArm", CubeListBuilder.create().texOffs(21, 1).addBox(-1.0F, -1.0F, 2.0F, 2.0F, 2.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(-7.0F, -5.0767F, -6.9556F));
		PartDefinition leftArm = arms.addOrReplaceChild("leftArm", CubeListBuilder.create().texOffs(7, 1).addBox(-1.0F, -1.0F, 2.0F, 2.0F, 2.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(7.0F, -5.0767F, -6.9556F));
		PartDefinition pot = brotecito.addOrReplaceChild("pot", CubeListBuilder.create(), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, -3.1416F, 0.0F, 3.1416F));
		PartDefinition frontPot = pot.addOrReplaceChild("frontPot", CubeListBuilder.create().texOffs(33, 62).addBox(-7.0F, -2.0F, 6.0F, 14.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition backPot = pot.addOrReplaceChild("backPot", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition backPot_r1 = backPot.addOrReplaceChild("backPot_r1", CubeListBuilder.create().texOffs(33, 59).addBox(-7.0F, -2.0F, 6.0F, 14.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, 3.1416F, 0.0F));
		PartDefinition leftPot = pot.addOrReplaceChild("leftPot", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition leftPot_r1 = leftPot.addOrReplaceChild("leftPot_r1", CubeListBuilder.create().texOffs(1, 53).addBox(-6.0F, -2.0F, 6.0F, 12.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, -1.5708F, 0.0F));
		PartDefinition rightPot = pot.addOrReplaceChild("rightPot", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition rightPot_r1 = rightPot.addOrReplaceChild("rightPot_r1", CubeListBuilder.create().texOffs(1, 56).addBox(-6.0F, -2.0F, 6.0F, 12.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, 1.5708F, 0.0F));
		PartDefinition upperLeftPot = pot.addOrReplaceChild("upperLeftPot", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition upperLeftPot_r1 = upperLeftPot.addOrReplaceChild("upperLeftPot_r1", CubeListBuilder.create().texOffs(0, 59).addBox(-8.0F, -3.0F, 7.0F, 15.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, -1.5708F, 0.0F));
		PartDefinition upperRightPot = pot.addOrReplaceChild("upperRightPot", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition upperRightPot_r1 = upperRightPot.addOrReplaceChild("upperRightPot_r1", CubeListBuilder.create().texOffs(29, 53).addBox(-8.0F, -3.0F, -8.0F, 16.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0.0F, -1.5708F, 0.0F));
		PartDefinition upperFrontPot = pot.addOrReplaceChild("upperFrontPot", CubeListBuilder.create().texOffs(0, 62).addBox(-8.0F, -3.0F, 7.0F, 15.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition upperBackPot = pot.addOrReplaceChild("upperBackPot", CubeListBuilder.create().texOffs(33, 56).addBox(-7.0F, -3.0F, -8.0F, 14.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		PartDefinition bottomPotFaceAndSoil = pot.addOrReplaceChild("bottomPotFaceAndSoil", CubeListBuilder.create().texOffs(15, 39).addBox(-6.0F, -1.0F, -6.0F, 12.0F, 1.0F, 12.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));

		return LayerDefinition.create(meshdefinition, 64, 64);
	}

	@Override
	public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
		brotecito.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
	}

	@Override
	public ModelPart root() {
		return brotecito;
	}

	public ModelPart getArmRight() {
		return brotecito.getChild("arms").getChild("rightArm");
	}

	@Override
	public void translateToHand(HumanoidArm p_102108_, PoseStack p_102109_) {
		this.getArmRight().translateAndRotate(p_102109_);
	}

	@Override
	public void setupAnim(T p_102618_, float p_102619_, float p_102620_, float p_102621_, float p_102622_, float p_102623_) {

	}
}

BrotecitoRenderer class

package com.example.examplemod.entity.client;

import com.example.examplemod.ExampleMod;
import com.example.examplemod.entity.custom.brotecito.BrotecitoEntity;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

public class BrotecitoRenderer extends MobRenderer<BrotecitoEntity, BrotecitoModel<BrotecitoEntity>> {
    public static final ResourceLocation TEXTURE = new ResourceLocation(ExampleMod.MODID, "textures/entity/brotecito.png");
    public BrotecitoRenderer(EntityRendererProvider.Context pContext) {
        super(pContext, new BrotecitoModel<>(pContext.bakeLayer(ModModelLayers.BROTECITO_LAYER)), 0.6f);
        this.addLayer(new ItemInHandLayer<>(this, pContext.getItemInHandRenderer()));
    }

    @Override
    public @NotNull ResourceLocation getTextureLocation(@NotNull BrotecitoEntity pEntity) {
        return TEXTURE;
    }

    @Override
    public void render(BrotecitoEntity pEntity, float pEntityYaw, float pPartialTicks, @NotNull PoseStack pMatrixStack,
                       @NotNull MultiBufferSource pBuffer, int pPackedLight) {
        if (pEntity.isBaby()) {
            pMatrixStack.scale(0.3f, 0.3f, 0.3f);
        }

        super.render(pEntity, pEntityYaw, pPartialTicks, pMatrixStack, pBuffer, pPackedLight);
    }
}

BrotecitoEntity class

package com.example.examplemod.entity.custom.brotecito;

import com.example.examplemod.entity.ModEntities;
import com.example.examplemod.particle.ModParticles;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.ai.goal.target.*;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Turtle;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.AbstractSkeleton;
import net.minecraft.world.entity.monster.Ghast;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.Team;
import net.minecraftforge.event.ForgeEventFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;

public class BrotecitoEntity extends TamableAnimal implements NeutralMob {
    @Nullable
    private UUID persistentAngerTarget;
    private static final UniformInt PERSISTENT_ANGER_TIME = UniformInt.of(20, 39);
    private static final EntityDataAccessor<Integer> DATA_REMAINING_ANGER_TIME = SynchedEntityData.defineId(BrotecitoEntity.class, EntityDataSerializers.INT);
    private static final EntityDataAccessor<Boolean> SITTING = SynchedEntityData.defineId(BrotecitoEntity.class, EntityDataSerializers.BOOLEAN);

    public BrotecitoEntity(EntityType<? extends TamableAnimal> pEntityType, Level pLevel) {
        super(pEntityType, pLevel);
        this.moveControl = new BrotecitoMoveControl(this);
    }

    // Método para que el Brotecito pueda obtener espadas de diamante y equiparlas
    @Override
    public void tick() {
        super.tick();

        if (!this.isAlive()) {
            return;
        }

        List<ItemEntity> itemsNearby = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(1.0));

        for (ItemEntity itemEntity : itemsNearby) {
            Item item = itemEntity.getItem().getItem();
            if (item == Items.DIAMOND_SWORD || item == Items.BOW) {
                // Recoger el Objeto
                this.take(itemEntity, itemEntity.getItem().getCount());

                // Equipar la espada
                this.setItemSlot(EquipmentSlot.MAINHAND, itemEntity.getItem());
                itemEntity.discard();
                break;
            }
        }
    }

    /**
     * Define el comportamiento de la IA del Brotecito
     */
    @Override
    protected void registerGoals() {
        this.goalSelector.addGoal(1, new BrotecitoFloatGoal(this));
        this.goalSelector.addGoal(2, new SitWhenOrderedToGoal(this));
        this.goalSelector.addGoal(4, new LeapAtTargetGoal(this, 0.4F));
        this.goalSelector.addGoal(5, new BrotecitoAttackGoal(this));
        this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0, 10.0F, 2.0F, false));
        this.goalSelector.addGoal(7, new BreedGoal(this, 1.0));
        this.goalSelector.addGoal(8, new BrotecitoRandomDirectionGoal(this));
        this.goalSelector.addGoal(9, new BrotecitoKeepOnJumpingGoal(this));
        this.goalSelector.addGoal(10, new LookAtPlayerGoal(this, Player.class, 8.0F));
        this.goalSelector.addGoal(10, new RandomLookAroundGoal(this));
        this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this));
        this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
        this.targetSelector.addGoal(3, (new HurtByTargetGoal(this)).setAlertOthers());
        this.targetSelector.addGoal(6, new NonTameRandomTargetGoal<>(this, Turtle.class, false, Turtle.BABY_ON_LAND_SELECTOR));
        this.targetSelector.addGoal(7, new NearestAttackableTargetGoal<>(this, AbstractSkeleton.class, false));
        this.targetSelector.addGoal(8, new ResetUniversalAngerTargetGoal<>(this, true));
    }

    public static AttributeSupplier.Builder createAttributes() {
        return Animal.createLivingAttributes()
                .add(Attributes.MAX_HEALTH, 20D)
                .add(Attributes.FOLLOW_RANGE, 24D)
                .add(Attributes.MOVEMENT_SPEED, 0.25D)
                .add(Attributes.ARMOR_TOUGHNESS, 0.1f)
                .add(Attributes.ATTACK_KNOCKBACK, 2f)
                .add(Attributes.ATTACK_DAMAGE, 2f);
    }

    @Nullable
    @Override
    public AgeableMob getBreedOffspring(@NotNull ServerLevel pLevel, @NotNull AgeableMob pOtherParent) {
        return ModEntities.BROTECITO.get().create(pLevel);
    }

    // Método para que los Brotecitos puedan emitir partículas personalizadas al aparearse
    @Override
    public void handleEntityEvent(byte id) {
        if (id == 18) {
            for(int i = 0; i < 7; i++) {
                double d0 = this.random.nextGaussian() * 0.02;
                double d1 = this.random.nextGaussian() * 0.02;
                double d2 = this.random.nextGaussian() * 0.02;
                this.level().addParticle(ModParticles.KAPPA_PRIDE_PARTICLES.get(), this.getRandomX(1.0),this.getRandomY() + 0.5, this.getRandomZ(1.0), d0, d1, d2);
            }
        } else {
            super.handleEntityEvent(id);
        }
    }

    @Override
    public boolean isFood(ItemStack pStack) {
        return pStack.is(Items.CARROT);
    }

    @Override
    public int getRemainingPersistentAngerTime() {
        return this.entityData.get(DATA_REMAINING_ANGER_TIME);
    }

    @Override
    public void setRemainingPersistentAngerTime(int i) {
        this.entityData.set(DATA_REMAINING_ANGER_TIME, i);
    }

    @Nullable
    @Override
    public UUID getPersistentAngerTarget() {
        return this.persistentAngerTarget;
    }

    @Override
    public void setPersistentAngerTarget(@Nullable UUID pTarget) {
        this.persistentAngerTarget = pTarget;
    }

    @Override
    public void startPersistentAngerTimer() {
        this.setRemainingPersistentAngerTime(PERSISTENT_ANGER_TIME.sample(this.random));
    }

    /* TAMEABLE */
    @Override
    public InteractionResult mobInteract(Player player, InteractionHand hand) {
        ItemStack itemStack = player.getItemInHand(hand);
        Item item = itemStack.getItem();

        Item itemForTaming = Items.APPLE;

        if (isFood(itemStack)) {
            return super.mobInteract(player, hand);
        }

        if (item == itemForTaming && !isTame()) {
            if (this.level().isClientSide) {
                return InteractionResult.CONSUME;
            } else {
                if (!player.getAbilities().instabuild) {
                    itemStack.shrink(1);
                }

                if (!ForgeEventFactory.onAnimalTame(this, player)) {
                    if (!this.level().isClientSide) {
                        super.tame(player);
                        this.navigation.recomputePath();
                        this.setTarget(null);
                        this.level().broadcastEntityEvent(this, (byte) 7);
                        setSitting(false);
                    }
                }

                return InteractionResult.SUCCESS;
            }
        }

        if (isTame() && !this.level().isClientSide && hand == InteractionHand.MAIN_HAND) {
            setSitting(!isSitting());
            return InteractionResult.SUCCESS;
        }

        if (itemStack.getItem() == itemForTaming) {
            return InteractionResult.PASS;
        }
        
        return super.mobInteract(player, hand);
    }

    // Método para que el Brotecito pueda atacar a entidades hostiles excepto a:
    // - Ghasts
    // - Brotecitos que no son suyos
    // - jugadores que no pueden ser dañados
    @Override
    public boolean wantsToAttack(@NotNull LivingEntity pTarget, @NotNull LivingEntity pOwner) {
        if (!(pTarget instanceof Ghast)) {
            if (pTarget instanceof BrotecitoEntity brotecitoEntity) {
                return !brotecitoEntity.isTame() || brotecitoEntity.getOwner() != pOwner;
            } else if (pTarget instanceof Player && pOwner instanceof Player && !((Player)pOwner).canHarmPlayer((Player)pTarget)) {
                return false;
            } else if (pTarget instanceof AbstractHorse && ((AbstractHorse)pTarget).isTamed()) {
                return false;
            } else {
                return !(pTarget instanceof TamableAnimal) || !((TamableAnimal)pTarget).isTame();
            }
        } else {
            return false;
        }
    }

    @Override
    public boolean isAlliedTo(Entity pEntity) {
        if (this.isTame() && this.getOwner() != null) {
            return pEntity == this.getOwner();
        } else {
            return super.isAlliedTo(pEntity);
        }
    }

    @Override
    public void readAdditionalSaveData(CompoundTag tag) {
        super.readAdditionalSaveData(tag);
        setSitting(tag.getBoolean("isSitting"));
    }

    @Override
    public void addAdditionalSaveData(CompoundTag tag) {
        super.addAdditionalSaveData(tag);
        tag.putBoolean("isSitting", this.isSitting());
    }

    // Método para que el Brotecito pueda sentarse y levantarse
    @Override
    protected void defineSynchedData() {
        super.defineSynchedData();
        this.entityData.define(SITTING, false);
    }

    public void setSitting(boolean sitting) {
        this.entityData.set(SITTING, sitting);
        this.setOrderedToSit(sitting);
    }

    public boolean isSitting() {
        return this.entityData.get(SITTING);
    }

    @Override
    public Team getTeam() {
        return super.getTeam();
    }

    public boolean canBeLeashed(Player player) {
        return false;
    }

    @Override
    public void setTame(boolean tamed) {
        super.setTame(tamed);
        if (tamed) {
            getAttribute(Attributes.MAX_HEALTH).setBaseValue(60.0D);
            getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(4D);
            getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.5f);
        } else {
            getAttribute(Attributes.MAX_HEALTH).setBaseValue(30.0D);
            getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(2D);
            getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.25f);
        }
    }

    public int getJumpDelay() {
        return this.random.nextInt(20) + 10;
    }

    protected void jumpFromGround() {
        Vec3 vec3 = this.getDeltaMovement();
        this.setDeltaMovement(vec3.x, this.getJumpPower(), vec3.z);
        this.hasImpulse = true;
    }

    protected float getJumpPower() {
        return 0.42F;
    }

    protected SoundEvent getJumpSound() {
        return SoundEvents.SLIME_JUMP;
    }

    protected float getSoundVolume() {
        return 0.4F;
    }

    protected float getSoundPitch() {
        float f = this.isTiny() ? 1.4F : 0.8F;
        return ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * f;
    }

    public boolean isTiny() {
        return false; // Puedes ajustar esta lógica según las necesidades de tu entidad
    }

    public void dealDamage(LivingEntity target) {
        if (this.isAlive() && this.distanceToSqr(target) < this.getBbWidth() * this.getBbWidth() && this.hasLineOfSight(target)) {
            boolean flag = target.hurt(target.damageSources().mobAttack(this), (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE));
            if (flag) {
                this.doEnchantDamageEffects(this, target);
                this.playSound(SoundEvents.IRON_GOLEM_ATTACK, 1.0F, 1.0F);
            }
        }
    }
}

I look forward to hearing from you, thank you very much in advance.

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.