Jump to content

Entity is being harmed when spawned


Spyeedy

Recommended Posts

For reasons I do not know, whenever I spawn my Entity, it gets harmed, there's nothing hitting it and yet it is still getting harmed.

How I know that it was being harmed? Answer: the Entity has red when it is being harmed.

Code:

[spoiler=Entity Class]

public class ExperimentalEntity extends EntityAnimal
{
    /** AI task for player control. */
    public final EntityAIControlledByPlayer aiControlledByPlayer;
    private static final UUID speed_UUID = UUID.fromString("e791d27a-5681-4ef1-8c96-fde0305527b5");
    private static final AttributeModifier speed_Modifier = (new AttributeModifier(speed_UUID, "Speed", 1.0D, 0));
    
public ExperimentalEntity(World worldIn)
{
	super(worldIn);
        this.tasks.addTask(0, this.aiControlledByPlayer = new EntityAIControlledByPlayer(this, 1.0F));
        this.isImmuneToFire = true;
}

@Override
public boolean isAIDisabled()
{
	return false;
}

@Override
protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
    }

@Override
protected void updateAITasks()
    {
        IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
        
        if (this.riddenByEntity instanceof EntityPlayer && !iattributeinstance.hasModifier(speed_Modifier))
        {
        	iattributeinstance.applyModifier(speed_Modifier);
        }
        else if (this.riddenByEntity == null && iattributeinstance.hasModifier(speed_Modifier))
        {
        	iattributeinstance.removeModifier(speed_Modifier);
        }

        super.updateAITasks();
    }

@Override
public boolean interact(EntityPlayer player)
    {
	 if(!worldObj.isRemote)
	 {
		 player.mountEntity(this);
	 }
	 if(riddenByEntity != null && (riddenByEntity instanceof EntityPlayer) && riddenByEntity != player)
	 {
		 return true;
	 }
	 else
	 {
		 return false;
	 }
    }

@Override
public boolean canBeSteered()
    {
        return true;
    }

@Override
public void updateRidden()
{
	if (ridingEntity.isDead)
	{
		ridingEntity = null;
		return;
	}
	motionX = motionY = motionZ = 0.0D;
	onUpdate();
	if (ridingEntity == null)
	{
		return;
	}
	ridingEntity.updateRiderPosition();
}

@Override
public boolean shouldRiderFaceForward(EntityPlayer player)
    {
        return this instanceof ExperimentalEntity;
    }

public EntityAIControlledByPlayer getAIControlledByPlayer()
    {
        return this.aiControlledByPlayer;
    }

@Override
public EntityAgeable createChild(EntityAgeable ageable)
{
	return null;
}
}

 

 

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

What version are you using? This isn't 1.10.

No it isn't, this is 1.8.9. I'm working out the problems first in 1.8.9 first then I will update it to 1.10

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

I don't really know the issue, but I have hints - not all of them might still be a thing (they were in about 1.8, maybe earlier).

 

Hurt animation (red) doesn't mean entity was damaged - it means it's health went down on client.

What is worth mentioning is that it also means that if you change maxHealth - it will reflect on health (to lower), thus, you will get hurt animation.

So the questions one may ask here:

* Was entity damaged on server, on client or both?

* Does entity have less health than max - on which sides?

* Is max health same on both sides?

* What damaged entity?

 

Since you have your own entity - you could override some methods and check what caused damage. You could also use events like EntityJoinedWorldEvent to check max health stats and LivingHurtEvent or other events (ConstructingEvent?)

 

The issue might not even be in entity itself - are you using something that could cause such issue? Events? World? Other entities? How do you spawn your entity?

Looking from 1.10 source, I don't see obvious error.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I don't really know the issue, but I have hints - not all of them might still be a thing (they were in about 1.8, maybe earlier).

 

Hurt animation (red) doesn't mean entity was damaged - it means it's health went down on client.

What is worth mentioning is that it also means that if you change maxHealth - it will reflect on health (to lower), thus, you will get hurt animation.

So the questions one may ask here:

* Was entity damaged on server, on client or both?

* Does entity have less health than max - on which sides?

* Is max health same on both sides?

* What damaged entity?

 

Since you have your own entity - you could override some methods and check what caused damage. You could also use events like EntityJoinedWorldEvent to check max health stats and LivingHurtEvent or other events (ConstructingEvent?)

 

The issue might not even be in entity itself - are you using something that could cause such issue? Events? World? Other entities? How do you spawn your entity?

Looking from 1.10 source, I don't see obvious error.

Uh well, my mod will not work on server side, so I do not know what's happening on server. Also, I tried removing the maxHealth attribute so the health will not change but to go down the drain, the entity still has the hurt animation (red).

[spoiler=Updated Code]

public class ExperimentalEntity extends EntityAnimal
{
    /** AI task for player control. */
    public final EntityAIControlledByPlayer aiControlledByPlayer;
    private static final UUID speed_UUID = UUID.fromString("e791d27a-5681-4ef1-8c96-fde0305527b5");
    private static final AttributeModifier speed_Modifier = (new AttributeModifier(speed_UUID, "Speed", 1.0D, 0));
    
public ExperimentalEntity(World worldIn)
{
	super(worldIn);
        this.tasks.addTask(0, this.aiControlledByPlayer = new EntityAIControlledByPlayer(this, 1.0F));
        this.isImmuneToFire = true;
}

@Override
public boolean isAIDisabled()
{
	return false;
}

@Override
protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
    }

@Override
protected void updateAITasks()
    {
        IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
        
        if (this.riddenByEntity instanceof EntityPlayer && !iattributeinstance.hasModifier(speed_Modifier))
        {
        	iattributeinstance.applyModifier(speed_Modifier);
        }
        else if (this.riddenByEntity == null && iattributeinstance.hasModifier(speed_Modifier))
        {
        	iattributeinstance.removeModifier(speed_Modifier);
        }

        super.updateAITasks();
    }

@Override
public boolean interact(EntityPlayer player)
    {
	 if(!worldObj.isRemote)
	 {
		 player.mountEntity(this);
	 }
	 if(riddenByEntity != null && (riddenByEntity instanceof EntityPlayer) && riddenByEntity != player)
	 {
		 return true;
	 }
	 else
	 {
		 return false;
	 }
    }

@Override
public boolean canBeSteered()
    {
        return true;
    }

@Override
public void updateRidden()
{
	if (ridingEntity.isDead)
	{
		ridingEntity = null;
		return;
	}
	motionX = motionY = motionZ = 0.0D;
	onUpdate();
	if (ridingEntity == null)
	{
		return;
	}
	ridingEntity.updateRiderPosition();
}

@Override
public boolean shouldRiderFaceForward(EntityPlayer player)
    {
        return this instanceof ExperimentalEntity;
    }

public EntityAIControlledByPlayer getAIControlledByPlayer()
    {
        return this.aiControlledByPlayer;
    }

@Override
public EntityAgeable createChild(EntityAgeable ageable)
{
	return null;
}
}

 

 

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

Uh well, my mod will not work on server side, so I do not know what's happening on server

If your mod doesn't work on a dedicated server, you've likely used Client only Classes or methods in code that is run on the server. If it doesn't work server-side, you've probably setup your proxies incorrectly.

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.