Skip to content

Commit

Permalink
Baby sheep color is now based off of the color of the parents like in…
Browse files Browse the repository at this point in the history
… vanilla Minecraft, instead of always being white. Cow, Deer, Pig, Sheep and Wolves now properly store the genetic modifiers of the father when breeding.
  • Loading branch information
Kittychanley committed May 18, 2016
1 parent 9dfe217 commit 04d3e28
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Common/com/bioxx/tfc/Entities/Mobs/EntityCowTFC.java
Expand Up @@ -537,7 +537,10 @@ public void mate(IAnimal otherAnimal)
pregnant = true;
resetInLove();
otherAnimal.setInLove(false);
mateAggroMod = otherAnimal.getAggressionMod();
mateObedMod = otherAnimal.getObedienceMod();
mateSizeMod = otherAnimal.getSizeMod();
mateStrengthMod = otherAnimal.getStrengthMod();
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/Common/com/bioxx/tfc/Entities/Mobs/EntityDeer.java
Expand Up @@ -528,7 +528,10 @@ public void mate(IAnimal otherAnimal)
pregnant = true;
resetInLove();
otherAnimal.setInLove(false);
mateAggroMod = otherAnimal.getAggressionMod();
mateObedMod = otherAnimal.getObedienceMod();
mateSizeMod = otherAnimal.getSizeMod();
mateStrengthMod = otherAnimal.getStrengthMod();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Common/com/bioxx/tfc/Entities/Mobs/EntityPigTFC.java
Expand Up @@ -524,7 +524,10 @@ public void mate(IAnimal otherAnimal)
pregnant = true;
resetInLove();
otherAnimal.setInLove(false);
mateAggroMod = otherAnimal.getAggressionMod();
mateObedMod = otherAnimal.getObedienceMod();
mateSizeMod = otherAnimal.getSizeMod();
mateStrengthMod = otherAnimal.getStrengthMod();
}

@Override
Expand Down
52 changes: 48 additions & 4 deletions src/Common/com/bioxx/tfc/Entities/Mobs/EntitySheepTFC.java
Expand Up @@ -6,11 +6,15 @@

import net.minecraft.entity.*;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.Vec3;
Expand Down Expand Up @@ -48,6 +52,14 @@ public class EntitySheepTFC extends EntitySheep implements IShearable, IAnimal
private static final float DIMORPHISM = 0.1633f;
private static final int DEGREE_OF_DIVERSION = 2;
private static final int FAMILIARITY_CAP = 35;
private final InventoryCrafting colorCrafting = new InventoryCrafting(new Container()
{
@Override
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
return false;
}
}, 2, 1);
/**
* Used to control movement as well as wool regrowth. Set to 40 on handleHealthUpdate and counts down with each
* tick.
Expand All @@ -66,6 +78,7 @@ public class EntitySheepTFC extends EntitySheep implements IShearable, IAnimal
private float mateStrengthMod;
private float mateAggroMod;
private float mateObedMod;
private int mateColor;
private float sizeMod; //How large the animal is
private float strengthMod; //how strong the animal is
private float aggressionMod = 1;//How aggressive / obstinate the animal is
Expand All @@ -92,6 +105,9 @@ public EntitySheepTFC(World par1World)
this.tasks.addTask(3, new EntityAIAvoidEntityTFC(this, EntityBear.class, 16f, 0.25F, 0.3F));
this.tasks.addTask(6, this.aiEatGrass);

this.colorCrafting.setInventorySlotContents(0, new ItemStack(Items.dye, 1, 0));
this.colorCrafting.setInventorySlotContents(1, new ItemStack(Items.dye, 1, 0));

hunger = 168000;
animalID = TFC_Time.getTotalTicks() + getEntityId();
pregnant = false;
Expand Down Expand Up @@ -190,6 +206,27 @@ public boolean checkFamiliarity(InteractionEnum interaction, EntityPlayer player
return flag;
}

public int combineColors(EntityAnimal parent, int mateColor)
{
int parent1Color = 15 - ((EntitySheep) parent).getFleeceColor();
int parent2Color = 15 - mateColor;
this.colorCrafting.getStackInSlot(0).setItemDamage(parent1Color);
this.colorCrafting.getStackInSlot(1).setItemDamage(parent2Color);
ItemStack itemstack = CraftingManager.getInstance().findMatchingRecipe(this.colorCrafting, ((EntitySheep) parent).worldObj);
int babyColor;

if (itemstack != null && itemstack.getItem() == Items.dye)
{
babyColor = itemstack.getItemDamage();
}
else
{
babyColor = this.worldObj.rand.nextBoolean() ? parent1Color : parent2Color;
}

return babyColor;
}

@Override
public EntitySheep createChild(EntityAgeable entityageable)
{
Expand All @@ -204,7 +241,10 @@ public EntityAgeable createChildTFC(EntityAgeable eAgeable)
data.add(eAgeable.getEntityData().getFloat("MateStrength"));
data.add(eAgeable.getEntityData().getFloat("MateAggro"));
data.add(eAgeable.getEntityData().getFloat("MateObed"));
return new EntitySheepTFC(worldObj, this, data);
EntitySheepTFC baby = new EntitySheepTFC(worldObj, this, data);
int colorMeta = this.combineColors(this, ((EntitySheepTFC) eAgeable).mateColor);
baby.setFleeceColor(15 - colorMeta);
return baby;
}

/**
Expand Down Expand Up @@ -556,7 +596,11 @@ public void mate(IAnimal otherAnimal)
pregnant = true;
resetInLove();
otherAnimal.setInLove(false);
mateAggroMod = otherAnimal.getAggressionMod();
mateObedMod = otherAnimal.getObedienceMod();
mateSizeMod = otherAnimal.getSizeMod();
mateStrengthMod = otherAnimal.getStrengthMod();
mateColor = ((EntitySheepTFC) otherAnimal).getFleeceColor();
}

/**
Expand Down Expand Up @@ -595,9 +639,7 @@ public void onLivingUpdate()
int i = rand.nextInt(3) + 1;
for (int x = 0; x < i; x++)
{
ArrayList<Float> data = new ArrayList<Float>();
data.add(mateSizeMod);
EntitySheepTFC baby = new EntitySheepTFC(worldObj, this, data);
EntitySheepTFC baby = (EntitySheepTFC) createChildTFC(this);
baby.setLocationAndAngles(posX, posY, posZ, 0.0F, 0.0F);
baby.rotationYawHead = baby.rotationYaw;
baby.renderYawOffset = baby.rotationYaw;
Expand Down Expand Up @@ -664,6 +706,7 @@ public void readEntityFromNBT(NBTTagCompound nbt)
mateStrengthMod = nbt.getFloat("MateStrength");
mateAggroMod = nbt.getFloat("MateAggro");
mateObedMod = nbt.getFloat("MateObed");
mateColor = nbt.getInteger("MateColor");
timeOfConception = nbt.getLong("ConceptionTime");
this.dataWatcher.updateObject(15, nbt.getInteger("Age"));
this.setAge(nbt.getInteger("Age"));
Expand Down Expand Up @@ -874,6 +917,7 @@ public void writeEntityToNBT(NBTTagCompound nbt)
nbt.setFloat("MateStrength", mateStrengthMod);
nbt.setFloat("MateAggro", mateAggroMod);
nbt.setFloat("MateObed", mateObedMod);
nbt.setInteger("MateColor", mateColor);
nbt.setLong("ConceptionTime", timeOfConception);
nbt.setInteger("Age", getBirthDay());
}
Expand Down
3 changes: 3 additions & 0 deletions src/Common/com/bioxx/tfc/Entities/Mobs/EntityWolfTFC.java
Expand Up @@ -637,7 +637,10 @@ public void mate(IAnimal otherAnimal)
resetInLove();
setInLove(false);
otherAnimal.setInLove(false);
mateAggroMod = otherAnimal.getAggressionMod();
mateObedMod = otherAnimal.getObedienceMod();
mateSizeMod = otherAnimal.getSizeMod();
mateStrengthMod = otherAnimal.getStrengthMod();
}

/**
Expand Down

0 comments on commit 04d3e28

Please sign in to comment.