Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey,

I know this is really REALLY simple and i'm ashamed for asking this but

 

I had the mob working fine with the attacking system, same as a zombie pigman but without the group attacking you

 

But I felt the code was really repetative so moved it into another Entity class so all mobs that work like that can extend it so i wont have the same code over and over again

 

So I've extended the class with the exact code from the mob class, but it's not attacking anything after it gets attacked

 

EntityPeacefullUntillAttacked

 

 

public abstract class EntityPeacefullUntillAttacked extends EntityDivineRPGMob {

private int angerLevel = 0;

public EntityPeacefullUntillAttacked(World w) {
	super(w);
}

@Override
public void writeEntityToNBT(NBTTagCompound nbt) {
	super.writeEntityToNBT(nbt);
	nbt.setShort("Anger", (short)this.angerLevel);
}

@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
	super.readEntityFromNBT(nbt);
	this.angerLevel = nbt.getShort("Anger");
}

@Override
public Entity findPlayerToAttack() {
	return this.angerLevel == 0 ? null : super.findPlayerToAttack();
}

@Override
public boolean attackEntityFrom(DamageSource src, float dmg) {
        if(this.isEntityInvulnerable()) {
            return false;
        } else {
            Entity entity = src.getEntity();
            if(entity instanceof EntityPlayer)
                this.becomeAngryAt(entity);
            return super.attackEntityFrom(src, dmg);
        }
    }

public boolean becomeAngryAt(Entity entity) {
	this.entityToAttack = entity;
	this.angerLevel = 1;
	return true;
}
}

 

 

 

 

And EntityDivineRPGMob if you wanted to see that class aswell

 

 


public EntityDivineRPGMob(World par1World) {
	super(par1World);
	LangRegistry.addMob(this);
        addBasicAI();
}

public void setMaxHP(double d){getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(100);}

public void setMoveSpeed(double d){getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.7);}

public void setAttackDamage(double d){getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(13);}

public void setFollowRange(double d){getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(100);}

public void setKnockbackResistance(double d){getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(100);}

public double getHP(){return getEntityAttribute(SharedMonsterAttributes.maxHealth).getAttributeValue();}

public double getMoveSpeed(){return getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();}

public double getAttackDamage(){return getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();}

public double getFollowRange(){return getEntityAttribute(SharedMonsterAttributes.followRange).getAttributeValue();}

public double getKnockbackResistance(){return getEntityAttribute(SharedMonsterAttributes.knockbackResistance).getAttributeValue();}

public abstract String mobName();

protected void addAttackingAI(){
        this.tasks.addTask(5, new EntityAIAttackOnCollide(this, EntityPlayer.class, getMoveSpeed(), false));
	this.targetTasks.addTask(6, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));

}

protected void addBasicAI(){
	this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIWander(this, getMoveSpeed()));
        this.tasks.addTask(2, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(3, new EntityAILookIdle(this));
}

@Override
protected boolean isAIEnabled() {
	return true;
}

public void onDeath(DamageSource d) {
	super.onDeath(d);
	if(!worldObj.isRemote && ConfigurationHelper.canShowDeathChat){
		if(d.getSourceOfDamage() != null && d.getSourceOfDamage() instanceof EntityPlayer){
			EntityPlayer p = (EntityPlayer)d.getSourceOfDamage();
			Util.sendMessageToAll(p.getDisplayName() + " has slain a " + mobName() + ".");

			if(d.getEntity() instanceof EntityTwins){
				Util.sendMessageToAll(p.getDisplayName() + " has slain the " + mobName() + ".");
			}
		}
	}
}
}

 

 

 

As i stated before, this is really simple and probably me being blind to see the problem, but if anyone can help, that would be great :)

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Hi

 

I'd suggest you trying adding breakpoints or System.out.println to your code (eg attackEntityFrom, findPlayerToAttack, etc) so that you can tell which parts are being called, and which ones aren't.  That will narrow it down a lot.

 

-TGG

Hi

 

I would suggest you drill further into here

@Override

public Entity findPlayerToAttack() {

return this.angerLevel == 0 ? null : super.findPlayerToAttack();

}

 

perhaps you angerLevel is wrong in this method, or alternatively super.findPlayerToAttack() is not what you think (are you extending EntityMob?)

 

Do you know how to use breakpoints?

If not, and you're using Eclipse, try this link...

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

 

 

-TGG

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.