Jump to content

Breeding two different animals


Dren

Recommended Posts

When u debugged the canmatewith method which you overrided, what happend when it was called?

 

o_o

uhm. Nothing happens ... I show you the AI i created and the canmatewith custom i made:

 

 

canMateWith

 

 

	public boolean canMateWith(EntityAnimal entity){
    	if (entity == this){
    		return false;
    	}else if ((this instanceof BullEntity) && (entity instanceof EntityCow)){
    		return this.isInLove() && entity.isInLove();
    	}else if ((this instanceof EntityCow) && (entity instanceof BullEntity)){
    		return this.isInLove() && entity.isInLove();
    	}
    	return false;
    }

 

 

 

AIMate

 

 

public class BullMate extends EntityAIBase{

Naturalia mod;

    World theWorld;
    private EntityAnimal theAnimal;
    private EntityAnimal targetMate;
    
private BullEntity bull;
private EntityCow cow;

    int spawnBabyDelay = 0;
    float moveSpeed;

    public BullMate(EntityAnimal animal, float par2){
        this.theAnimal = animal;
        this.theWorld = animal.worldObj;
        this.moveSpeed = par2;
        this.setMutexBits(3);
    }

    public boolean shouldExecute() {
        if (!this.theAnimal.isInLove()) {
            return false;
        } else {
            this.targetMate = this.getNearbyMate();
            return this.targetMate != null;
        }
    }
    
    public boolean continueExecuting() {
        return this.targetMate.isEntityAlive() && this.targetMate.isInLove() && this.spawnBabyDelay < 60;
    }
    
    public void resetTask() {
        this.targetMate = null;
        this.spawnBabyDelay = 0;
    }

    public void updateTask() {
        this.theAnimal.getLookHelper().setLookPositionWithEntity(this.targetMate, 10.0F, (float)this.theAnimal.getVerticalFaceSpeed());
        this.theAnimal.getNavigator().tryMoveToEntityLiving(this.targetMate, this.moveSpeed);
        ++this.spawnBabyDelay;

        if (this.spawnBabyDelay == 60) {
            this.spawnBaby();
        }
    }

    private EntityAnimal getNearbyMate(){
    	float boundExpand = 8.0F;
    	List nearbyEntities = this.theWorld.getEntitiesWithinAABB(this.theAnimal.getClass(), this.theAnimal.boundingBox.expand((double)boundExpand, (double)boundExpand, (double)boundExpand));
    	Iterator findEntity = nearbyEntities.iterator();
    	EntityAnimal mateEntity;

    	do {
    		if (!findEntity.hasNext()){
    			return null;
    		}

    		mateEntity = (EntityAnimal)findEntity.next();
    	}
    	while (!this.theAnimal.canMateWithNaturalia(mateEntity));

    	return mateEntity;
    }

    private void spawnBaby() {
        EntityAgeable var1 = this.theAnimal.func_90011_a(this.targetMate);
        
        if (var1 != null)  {
            this.theAnimal.setGrowingAge(6000);
            this.targetMate.setGrowingAge(6000);
            this.theAnimal.resetInLove();
            this.targetMate.resetInLove();
            var1.setGrowingAge(-24000);
            var1.setLocationAndAngles(this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, 0.0F, 0.0F);
            this.theWorld.spawnEntityInWorld(var1);
            Random var2 = this.theAnimal.getRNG();

            for (int var3 = 0; var3 < 7; ++var3) {
                double var4 = var2.nextGaussian() * 0.02D;
                double var6 = var2.nextGaussian() * 0.02D;
                double var8 = var2.nextGaussian() * 0.02D;
                this.theWorld.spawnParticle("heart", this.theAnimal.posX + (double)(var2.nextFloat() * this.theAnimal.width * 2.0F) - (double)this.theAnimal.width, this.theAnimal.posY + 0.5D + (double)(var2.nextFloat() * this.theAnimal.height), this.theAnimal.posZ + (double)(var2.nextFloat() * this.theAnimal.width * 2.0F) - (double)this.theAnimal.width, var4, var6, var8);
            }
            this.theWorld.spawnEntityInWorld(new EntityXPOrb(this.theWorld, this.theAnimal.posX, this.theAnimal.posY, this.theAnimal.posZ, var2.nextInt(7) + 1));
        }
    }
}

 

 

 

 

BullEntity

 

 

public class BullEntity extends EntityAnimal{

public BullEntity(World par1World){
	super(par1World);
        this.texture = "/Naturalia/mobs/Bull.png";
        this.setSize(0.9F, 1.3F);
        this.getNavigator().setAvoidsWater(true);
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIPanic(this, 0.38F));
        this.tasks.addTask(2, new BullMate(this, 0.2F));
        this.tasks.addTask(3, new EntityAITempt(this, 0.25F, Item.wheat.shiftedIndex, false));
        this.tasks.addTask(4, new EntityAIFollowParent(this, 0.25F));
        this.tasks.addTask(5, new EntityAIWander(this, 0.2F));
        this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.tasks.addTask(7, new EntityAILookIdle(this));
    }

    public String getTexture(){
    	if (this.isChild()){
    		return "/Naturalia/mobs/BullChild.png";
    	}else{
    		return "/Naturalia/mobs/Bull.png";
    	}
    }

    public boolean isAIEnabled(){
        return true;
    }

    public int getMaxHealth(){
        return 10;
    }

    protected String getLivingSound(){
        return "mob.cow.say";
    }
    protected String getHurtSound(){
        return "mob.cow.hurt";
    }
    protected String getDeathSound(){
        return "mob.cow.hurt";
    }
    protected void playStepSound(int par1, int par2, int par3, int par4){
        this.func_85030_a("mob.cow.step", 0.15F, 1.0F);
    }
    protected float getSoundVolume(){
        return 0.4F;
    }

    protected int getDropItemId(){
        return Item.leather.shiftedIndex;
    }

    protected void dropFewItems(boolean par1, int par2){
        int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);
        int var4;

        for (var4 = 0; var4 < var3; ++var4){
            this.dropItem(Item.leather.shiftedIndex, 1);
        }

        var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2);

        for (var4 = 0; var4 < var3; ++var4){
            if (this.isBurning()){
                this.dropItem(Item.beefCooked.shiftedIndex, 1);
            }else{
                this.dropItem(Item.beefRaw.shiftedIndex, 1);
            }
        }
    }

    public boolean interact(EntityPlayer player){
        ItemStack item = player.inventory.getCurrentItem();

        if (item != null && this.isBreedingItem(item) && this.getGrowingAge() == 0){
            if (!player.capabilities.isCreativeMode){
                --item.stackSize;

                if (item.stackSize <= 0){
                	player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
                }
            }

            this.inLove = 600;
            this.entityToAttack = null;

            for (int var3 = 0; var3 < 7; ++var3){
                double var4 = this.rand.nextGaussian() * 0.02D;
                double var6 = this.rand.nextGaussian() * 0.02D;
                double var8 = 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, var4, var6, var8);
            }
            
            return true;
        } else {
            return super.interact(player);
        }
    }

    /**
     * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
     */
  
    public BullEntity spawnBabyAnimal(EntityAgeable par1EntityAgeable) {
        return new BullEntity(this.worldObj);
    }

    public EntityAgeable func_90011_a(EntityAgeable par1EntityAgeable) {
        return this.spawnBabyAnimal(par1EntityAgeable);
    }
}

 

 

 

what about extending entity bull by entity cow ?

so the bull gets recognized as a cow, not another entityliving.

 

dont know if that works though.

 

I thought of this as well but I just want cow and bull to breed, not cow and cow or bull and bull T_T

 

Link to comment
Share on other sites

nothing happends? as inn the code is never called? the breakpoints never seems to be passed or?

 

 

The cows keep mating each others, as well as bull; bulls and cows don't mate.

 

It's like the mod doesn't see my changes.

 

Sorry for my bad english :(

Link to comment
Share on other sites

Thats not what I asked, I asked what happends when the code execute, when the code runs. What happends the exact moment each line of code runs trough the method?

 

Not what you see in-game but what do you see inn the code when it checks cow against bull?

 

If you can't tell me this, I promise you what you really need above and before all is to learn some programming somewhere before modding a game..

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

let me be even more specific inn my question:

 

What happends when THIS line is run?

}else if ((this instanceof BullEntity) && (entity instanceof EntityCow)){

Do you know what this code is checking for?

 

The mod doesn't get to that point :(

 

 

Link to comment
Share on other sites

  • 2 years later...

I know this thread has been closed for a while, but for anyone who has this problem, SenpaiSubaraki's suggestion works. Make one of the entities extend the other, then use the canmatewith method code Dren created in each of the entities.

Before you say that I need to learn java, I will have you know that I have completed an advanced java course from johns hopkins university with an A- average.

Thanks, and have a nice day and a smiley :)

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.