Jump to content

Further Entity Help


Lua

Recommended Posts

Hi,

 

So I'm here again, requesting further help on this entity, although the past two times I managed to work the problem out myself. But this, this one is just weird. I'm not sure if its me, or mc code. Anway, this mp4 describes the problem. http://gyazo.com/7077bbd220c167afdff66df647b84659 This only happens if you stand in a specific position, and it can sometimes happen when it trys to jump and hit you. As you can see, the mob is clearly hitting the player but the player isn't taking damage. I must stress, this is only if you stand like this, most of the time you wouldn't notice it in combat. Could this minecrafts bad attacking AI's fault? Anyway, just to be certain, my codes below for you to check over.

 

package mcub.entities;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class OS_EntityQueenSpider extends EntitySpider implements IBossDisplayData
{

private int healAtDifferentDifficulties;

public OS_EntityQueenSpider(World world)
{
	super(world);
	this.setSize(2.8F, 1.5F);
	this.isImmuneToFire = true;
	this.experienceValue = 100;
}

@Override
protected void applyEntityAttributes()
{
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(100.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(1.99900011920929D);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(9.0D);
	this.getEntityAttribute(SharedMonsterAttributes.followRange).setAttribute(40.0D);
	this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setAttribute(1.0);
}

private void playHealthEffect()
{

	for(int i = 0; i < 4; ++i)
	{
		double d0 = this.rand.nextGaussian() * 0.02D;
		double d1 = this.rand.nextGaussian() * 0.02D;
		double d2 = this.rand.nextGaussian() * 0.02D;
		this.worldObj.spawnParticle("heart", this.posX + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width, this.posY + 0.5D + (double) (this.rand.nextFloat() * this.height), this.posZ + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width, d0, d1,
				d2);
	}
}

//Removed the check for daylight. 
@Override
protected Entity findPlayerToAttack()
{
	return this.worldObj.getClosestVulnerablePlayerToEntity(this, 40);
}

@Override
public boolean attackEntityAsMob(Entity ent)
{
	if(super.attackEntityAsMob(ent))
	{
		if(ent instanceof EntityLivingBase)
		{
			//TODO add potion
			super.attackEntityAsMob(ent);
		}
		return true;
	}
	else
	{
		return false;
	}
}

@Override
public void onLivingUpdate()
{
	switch(Minecraft.getMinecraft().gameSettings.difficulty)
	{
	case 1:
		healAtDifferentDifficulties = 20;
		break;
	case 2:
		healAtDifferentDifficulties = 40;
		break;
	case 3:
		healAtDifferentDifficulties = 60;
		break;
	}
	if(this.getHealth() < healAtDifferentDifficulties && this.ticksExisted % 20 == 0)
	{
		this.heal(2.0F);
		playHealthEffect();
	}
	super.onLivingUpdate();
}

@Override
public void onDeath(DamageSource damageSource)
{
	OS_EntityEnderSpider enderSpider = new OS_EntityEnderSpider(this.worldObj);
	enderSpider.setPosition(this.posX, this.posY, this.posZ);
	this.worldObj.spawnEntityInWorld(enderSpider);
}

}

 

Results from my debugging:

- It's not because I'm extending EntitySpider

- It's not because i've up-scaled the mob.

- It's not because of the onLivingUpdate method somehow causing it to bug out.

 

 

The chance of it being a hitbox problem crossed my mind too, so heres a picture of the mobs hitbox.  http://gyazo.com/37d0d67b0fc30eea7a560cedde63f1c3

Link to comment
Share on other sites

Hi

 

What I mean is -  you put a breakpoint in (say) attackEntityAsMob, and then when your player is attacked the code stops executing and you step through your code one line at a time.  At some point it will do something different to what you expect (i.e. won't cause damage) and give you a clue what's wrong.

 

Have you used breakpoints and watches like this before?  They are extremely useful, not just for crashes, for example see here

http://www.vogella.com/articles/EclipseDebugging/article.html

 

Alternatively you can add logging statements to key points in your code, for example you might use:

 

	@Override
public boolean attackEntityAsMob(Entity ent)
{
System.out.println("attackEntityAsMob entered");
	if(super.attackEntityAsMob(ent))
	{
System.out.println("attackEntityAsMob -A ");

		if(ent instanceof EntityLivingBase)
		{
System.out.println("ent instanceof EntityLivingBase ");
			//TODO add potion
			super.attackEntityAsMob(ent);
		}
System.out.println("attackEntityAsMob returning true ");
		return true;
	}
	else
	{
System.out.println("attackEntityAsMob returning false ");
		return false;
	}
}

That's a bit overdone but you get the idea.  Any time you're not sure which parts of your code are being executed, or you want to know what the value of a variable is at a certain point, you add a logging statement.  If you've chosen well, the logging statements will either confirm that a part of your code is working correctly or will show that it's not doing what you assumed.  Once you narrow it down a bit, you add some more statements, recompile and run again, and keep doing that until you have tracked down the problem. You can add logging statements to the vanilla code too, just remember to remove them again later.

 

-TGG

 

 

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.