Jump to content

[1.10.2] Entities don't watch the player with body and head


RickWeek

Recommended Posts

1 hour ago, RickWeek said:

Hi, i need help with a bug that i can't fix.

I created some entities and when they attack the player them bodies and heads don't follow the player but are rounded sometimes to other direction but they walking to the player

So... how can we help without your code & logs?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Sorry, you're right.

This is the model code:

Spoiler

package com.rickweek.models;

import com.rickweek.entities.CREEPSEntityCastleGuard;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.math.MathHelper;

public class CREEPSModelCastleGuard extends ModelBase
{
    public ModelRenderer bipedHead;
    public ModelRenderer bipedBody;
    public ModelRenderer bipedRightArm;
    public ModelRenderer bipedLeftArm;
    public ModelRenderer bipedRightLeg;
    public ModelRenderer bipedLeftLeg;

    /**
     * Records whether the model should be rendered holding an item in the left hand, and if that item is a block.
     */
    public boolean heldItemLeft;

    /**
     * Records whether the model should be rendered holding an item in the right hand, and if that item is a block.
     */
    public boolean heldItemRight;
    public boolean isSneak;
    public ModelRenderer hammerHandle;
    public ModelRenderer hammerHead;
    public ModelRenderer bootR;
    public ModelRenderer bootL;
    public ModelRenderer footL;
    public ModelRenderer footR;
    public ModelRenderer earL;
    public ModelRenderer earR;
    public ModelRenderer nose;
    public float hammerswing;

    public CREEPSModelCastleGuard()
    {
        this(0.0F);
    }

    public CREEPSModelCastleGuard(float f)
    {
        this(f, 0.0F);
    }

    public CREEPSModelCastleGuard(float f, float f1)
    {
        float f2 = 0.0F;
        bipedHead = new ModelRenderer(this, 0, 0);
        bipedHead.addBox(-2F, -9F, -4F, 4, 9, 7, 0.0F);
        bipedHead.setRotationPoint(0.0F, 0.0F, 0.0F);
        bipedBody = new ModelRenderer(this, 24, 16);
        bipedBody.addBox(-4F, 0.0F, -2F, 8, 12, 4, 0.0F);
        bipedBody.setRotationPoint(0.0F, 0.0F, 0.0F);
        bipedRightArm = new ModelRenderer(this, 48, 16);
        bipedRightArm.addBox(-3F, -2F, -2F, 4, 12, 4, 0.0F);
        bipedRightArm.setRotationPoint(-5F, 2.0F, 0.0F);
        bipedRightArm.rotateAngleX = -0.5235988F;
        bipedLeftArm = new ModelRenderer(this, 48, 16);
        bipedLeftArm.addBox(-1F, -2F, -2F, 4, 12, 4, 0.0F);
        bipedLeftArm.setRotationPoint(5F, 2.0F, 0.0F);
        bipedRightLeg = new ModelRenderer(this, 0, 17);
        bipedRightLeg.addBox(-1.5F, 0.0F, -1.5F, 3, 12, 3, 0.0F);
        bipedRightLeg.setRotationPoint(-2F, 12F, 0.0F);
        bipedLeftLeg = new ModelRenderer(this, 0, 17);
        bipedLeftLeg.addBox(-1.5F, 0.0F, -1.5F, 3, 12, 3, 0.0F);
        bipedLeftLeg.setRotationPoint(2.5F, 12F, 0.0F);
        hammerHandle = new ModelRenderer(this, 24, 0);
        hammerHandle.addBox(-2F, 8F, -12F, 1, 1, 15, 0.25F);
        hammerHandle.setRotationPoint(-5F, 2.0F, 0.0F);
        hammerHandle.rotateAngleX = -0.5235988F;
        hammerHead = new ModelRenderer(this, 12, 22);
        hammerHead.addBox(-3F, 5F, -11F, 3, 7, 3, 0.25F);
        hammerHead.setRotationPoint(-5F, 2.0F, 0.0F);
        hammerHead.rotateAngleX = -0.5235988F;
        bootR = new ModelRenderer(this, 48, 0);
        bootR.addBox(-2F, 7F, -2F, 4, 5, 4, 0.0F);
        bootR.setRotationPoint(-2F, 12F, 0.0F);
        bootL = new ModelRenderer(this, 48, 0);
        bootL.addBox(-2F, 7F, -2F, 4, 5, 4, 0.0F);
        bootL.setRotationPoint(2.5F, 12F, 0.0F);
        footL = new ModelRenderer(this, 48, 9);
        footL.addBox(-2F, 10F, -4.5F, 4, 2, 3, 0.0F);
        footL.setRotationPoint(2.5F, 12F, 0.0F);
        footR = new ModelRenderer(this, 48, 9);
        footR.addBox(-2F, 10F, -4.5F, 4, 2, 3, 0.0F);
        footR.setRotationPoint(-2F, 12F, 0.0F);
        earL = new ModelRenderer(this, 12, 17);
        earL.addBox(2.0F, -7F, -1F, 1, 2, 1, 0.0F);
        earL.setRotationPoint(0.0F, 0.0F, 0.0F);
        earR = new ModelRenderer(this, 12, 17);
        earR.addBox(-3F, -7F, -1F, 1, 2, 1, 0.0F);
        earR.setRotationPoint(0.0F, 0.0F, 0.0F);
        nose = new ModelRenderer(this, 16, 17);
        nose.addBox(-0.5F, -6F, -5F, 1, 1, 3, 0.0F);
        nose.setRotationPoint(0.0F, 0.0F, 0.0F);
        nose.rotateAngleX = 0.2230717F;
    }

    /**
     * Sets the models various rotation angles then renders the model.
     */
    public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
    {
        setRotationAngles(f, f1, f2, f3, f4, f5);
        bipedHead.render(f5);
        bipedBody.render(f5);
        bipedRightArm.render(f5);
        bipedLeftArm.render(f5);
        bipedRightLeg.render(f5);
        bipedLeftLeg.render(f5);
        hammerHandle.render(f5);
        hammerHead.render(f5);
        bootR.render(f5);
        bootL.render(f5);
        footL.render(f5);
        footR.render(f5);
        earL.render(f5);
        earR.render(f5);
        nose.render(f5);
    }
    
    public void setLivingAnimations(EntityLiving entityliving, float f, float f1, float f2)
    {
        CREEPSEntityCastleGuard creepsentitycastleguard = (CREEPSEntityCastleGuard)entityliving;

        if (creepsentitycastleguard.getSwinging())
        {
            hammerHead.rotateAngleX = hammerHandle.rotateAngleX = bipedRightArm.rotateAngleX = creepsentitycastleguard.getHammerSwing();
        }
        else
        {
            hammerHead.rotateAngleX = hammerHandle.rotateAngleX = bipedRightArm.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 2.0F * f1 * 0.5F;
        }
    }
    

    /**
     * Sets the models various rotation angles.
     */
    public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
    {
        earL.rotateAngleY = earR.rotateAngleY = nose.rotateAngleY = bipedHead.rotateAngleY = f3 / (180F / (float)Math.PI);
        earL.rotateAngleX = earR.rotateAngleX = nose.rotateAngleX = bipedHead.rotateAngleX = f4 / (180F / (float)Math.PI);
        nose.rotateAngleX += 0.2230717F;

        if (hammerswing != 0.0F)
        {
            hammerHead.rotateAngleX = hammerHandle.rotateAngleX = bipedRightArm.rotateAngleX = hammerswing;
        }
        else
        {
            hammerHead.rotateAngleX = hammerHandle.rotateAngleX = bipedRightArm.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 2.0F * f1 * 0.5F;
        }

        bipedLeftArm.rotateAngleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5F;
        hammerHead.rotateAngleZ = hammerHandle.rotateAngleZ = bipedRightArm.rotateAngleZ = 0.0F;
        bipedLeftArm.rotateAngleZ = 0.0F;
        bootR.rotateAngleX = footR.rotateAngleX = bipedRightLeg.rotateAngleX = MathHelper.cos(f * 0.6662F) * 1.4F * f1;
        bootL.rotateAngleX = footL.rotateAngleX = bipedLeftLeg.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 1.4F * f1;
        bootR.rotateAngleY = footR.rotateAngleY = bipedRightLeg.rotateAngleY = 0.0F;
        bootL.rotateAngleY = footL.rotateAngleY = bipedLeftLeg.rotateAngleY = 0.0F;
        bipedRightArm.rotateAngleZ += MathHelper.cos(f2 * 0.09F) * 0.05F + 0.05F;
        hammerHead.rotateAngleZ += MathHelper.cos(f2 * 0.09F) * 0.05F + 0.05F;
        hammerHandle.rotateAngleZ += MathHelper.cos(f2 * 0.09F) * 0.05F + 0.05F;
        bipedLeftArm.rotateAngleZ -= MathHelper.cos(f2 * 0.09F) * 0.05F + 0.05F;
        bipedRightArm.rotateAngleX += MathHelper.sin(f2 * 0.067F) * 0.05F;
        hammerHead.rotateAngleX += MathHelper.sin(f2 * 0.067F) * 0.05F;
        hammerHandle.rotateAngleX += MathHelper.sin(f2 * 0.067F) * 0.05F;
        bipedLeftArm.rotateAngleX -= MathHelper.sin(f2 * 0.067F) * 0.05F;
    }
}

 

 

This is the render:

Spoiler

package com.rickweek.mob.renders;

import org.lwjgl.opengl.GL11;

import com.rickweek.entities.CREEPSEntityCastleGuard;
import com.rickweek.models.CREEPSModelCastleGuard;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

public class CREEPSRenderCastleGuard extends RenderLiving
{
    protected CREEPSModelCastleGuard modelcastleguardmain;

    public CREEPSRenderCastleGuard(RenderManager renderManager, CREEPSModelCastleGuard creepsmodelcastleguard, float f)
    {
        super(Minecraft.getMinecraft().getRenderManager(), creepsmodelcastleguard, f);
        modelcastleguardmain = creepsmodelcastleguard;
    }

    protected void fattenup(CREEPSEntityCastleGuard creepsentitycastleguard, float f)
    {
        GL11.glScalef(creepsentitycastleguard.modelsize, creepsentitycastleguard.modelsize, creepsentitycastleguard.modelsize);
    }
    protected void preRenderCallback(EntityLivingBase entityliving, float f)
    {
        CREEPSEntityCastleGuard creepsentitycastleguard = (CREEPSEntityCastleGuard)entityliving;
        modelcastleguardmain.hammerswing = creepsentitycastleguard.hammerswing;
        fattenup((CREEPSEntityCastleGuard)entityliving, f);
    }
    
    protected float getHammerSwing(CREEPSEntityCastleGuard creepsentitycastleguard, float f)
    {
        return creepsentitycastleguard.getHammerSwing();
    }

    protected float handleHammerFloat(EntityLiving entityliving, float f)
    {
        return getHammerSwing((CREEPSEntityCastleGuard)entityliving, f);
    }

    protected boolean getSwinging(CREEPSEntityCastleGuard creepsentitycastleguard, boolean flag)
    {
        return creepsentitycastleguard.getSwinging();
    }

    protected boolean handleRotationBoolean(EntityLiving entityliving, boolean flag)
    {
        return getSwinging((CREEPSEntityCastleGuard)entityliving, flag);
    }

    protected ResourceLocation getEntityTexture(CREEPSEntityCastleGuard entity)
    {
		return new ResourceLocation(entity.texture);
	}

	protected ResourceLocation getEntityTexture(Entity entity) {

		return getEntityTexture((CREEPSEntityCastleGuard) entity);
	}
}

 

 

 

This is the entity:

Spoiler

package com.rickweek.entities;

import com.rickweek.init.MCItems;
import com.rickweek.init.MCSoundEvents;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class CREEPSEntityCastleGuard extends EntityMob
{
    private int angerLevel;
    private int randomSoundDelay;
    public String basetexture;
    public int attackdamage;
    public boolean isSwinging;
    public boolean swingArm;
    public int swingTick;
    public String texture;
    public boolean attacked;
    public float hammerswing;
    public float modelsize;
    static final String guardTextures[] =
    {
        "mcw:textures/entity/castleguard1.png", "mcw:textures/entity/castleguard2.png", "mcw:textures/entity/castleguard3.png", "mcw:textures/entity/castleguard4.png", "mcw:textures/entity/castleguard5.png"
    };

    public CREEPSEntityCastleGuard(World world) {
        super(world);
        angerLevel = 0;
        randomSoundDelay = 0;
        basetexture = guardTextures[rand.nextInt(guardTextures.length)];
        texture = basetexture;
        attacked = false;
        hammerswing = 0.0F;
        modelsize = 1.0F;
        attackdamage = 1;
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(2, new EntityAIMoveTowardsRestriction(this, 0.5D));
        this.tasks.addTask(5, new CREEPSEntityCastleGuard.AIAttackTarget());
        this.tasks.addTask(3, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(4, new EntityAILookIdle(this));
        this.tasks.addTask(1, new EntityAIAttackMelee(this, 1.0D, true));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0]));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));

    }
    
    public void applyEntityAttributes() {
    	super.applyEntityAttributes();
    	this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D);
    	this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000005D);
    	this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(1D);
    }
    
    public boolean getSwinging()
    {
        return hammerswing != 0.0F;
    }
    
    public float getHammerSwing()
    {
        return hammerswing;
    }
    
    /**
     * Called to update the entity's position/logic.
     */
    public void onUpdate() {
        if (hammerswing < 0.0F)
        {
            hammerswing += 0.45F;
        }
        else
        {
            hammerswing = 0.0F;
        }

        super.onUpdate();
    }


    public int getMaxSpawnedInChunk() {
        return 2;
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    public void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
        super.writeEntityToNBT(nbttagcompound);
        nbttagcompound.setShort("Anger", (short)angerLevel);
        nbttagcompound.setBoolean("Attacked", attacked);
        nbttagcompound.setString("BaseTexture", basetexture);
        nbttagcompound.setFloat("ModelSize", modelsize);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
        super.readEntityFromNBT(nbttagcompound);
        angerLevel = nbttagcompound.getShort("Anger");
        nbttagcompound.setBoolean("Attacked", attacked);
        nbttagcompound.setString("BaseTexture", basetexture);
        modelsize = nbttagcompound.getFloat("ModelSize");
        texture = basetexture;
    }

    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource damagesource, int i)
    {
        Entity entity = damagesource.getEntity();

        if (entity instanceof EntityPlayer)
        {
            attacked = true;
        }

        return super.attackEntityFrom(DamageSource.causeMobDamage(this), i);
    }

    /**
     * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define their attack.
     */
    protected void attackEntity(Entity entity, float f)
    {
        if (onGround)
        {
        	
            double d = entity.posX - posX;
            double d2 = entity.posZ - posZ;
            float f1 = MathHelper.sqrt_double(d * d + d2 * d2);
            motionX = (d / (double)f1) * 0.20000000000000001D * (0.58000001192092898D + motionX * 0.20000000298023224D);
            motionZ = (d2 / (double)f1) * 0.20000000000000001D * (0.52200000119209289D + motionZ * 0.20000000298023224D);
            motionY = 0.19500000596246447D;
            fallDistance = -25F;

        }

        if ((double)f > 3D && rand.nextInt(10) == 0)
        {
            double d1 = -MathHelper.sin((rotationYaw * (float)Math.PI) / 180F);
            double d3 = MathHelper.cos((rotationYaw * (float)Math.PI) / 180F);
            motionX += d1 * 0.10999999940395355D;
            motionZ += d3 * 0.10999999940395355D;
            motionY += 0.023000000044703484D;
        } 

        if ((double)f < 2.2999999999999998D - (1.0D - (double)modelsize) && entity.getEntityBoundingBox().maxY > entity.getEntityBoundingBox().minY && entity.getEntityBoundingBox().minY < entity.getEntityBoundingBox().maxY && !(entity instanceof CREEPSEntityCastleGuard))
        {
            if (hammerswing == 0.0F)
            {
                hammerswing = -2.6F;
            }

            entity.attackEntityFrom(DamageSource.causeMobDamage(this), attackdamage);
        }
    }
    
    public class AIAttackTarget extends EntityAIBase {

    	public CREEPSEntityCastleGuard castleguard = CREEPSEntityCastleGuard.this;
    	public AIAttackTarget() {}
    	
		@Override
		public boolean shouldExecute() {
            EntityLivingBase entitylivingbase = this.castleguard.getAttackTarget();
            return entitylivingbase != null && entitylivingbase.isEntityAlive();
		}
        public void updateTask()
        {
            EntityLivingBase entitylivingbase = this.castleguard.getAttackTarget();
            double d0 = this.castleguard.getDistanceSqToEntity(entitylivingbase);

            if (d0 < 4.0D) {
            	this.castleguard.attackEntityAsMob(entitylivingbase);
                this.castleguard.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
            }
            else if (d0 < 256.0D) {
            	castleguard.attackEntity(entitylivingbase, (float)d0);
                this.castleguard.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
            }
            else {
                this.castleguard.getNavigator().clearPathEntity();
                this.castleguard.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 0.5D);
            }
        }
    }

    private void becomeAngryAt(Entity entity) {
        this.attackEntity(entity, 1);
        angerLevel = 400 + rand.nextInt(400);
        randomSoundDelay = rand.nextInt(40);
    }

    // Ritorna il danno riprodotto dal mob quando e vivo
    protected SoundEvent getLivingSound()
    {
        if (attacked && rand.nextInt(5) == 0)
        {
        	return MCSoundEvents.ENTITY_CASTLEGUARD_MAD;
        }

        if (rand.nextInt(12) == 0)
        {
        	return MCSoundEvents.ENTITY_CASTLEGUARD;
        }
        else
        {
            return null;
        }
    }

    // Ritorna il danno riprodotto dal mob quando viene colpito
    protected SoundEvent getHurtSound()
    {
        return MCSoundEvents.ENTITY_CASTLEGUARD_HURT;
    }

    // Ritorna il danno riprodotto dal mob alla sua morte
    protected SoundEvent getDeathSound()
    {
    	return MCSoundEvents.ENTITY_CASTLEGUARD_DEATH;
    }

    // Alla morte dell'entita
    public void onDeath(DamageSource damagesource) {
        super.onDeath(damagesource);
        if(!worldObj.isRemote)
            if (rand.nextInt(3) == 0) 
                dropItem(MCItems.Donut, rand.nextInt(2) + 1);
            
    }
}

 

 

 

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.