Skip to content

Commit

Permalink
Owl Genetics
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed Feb 19, 2016
1 parent 6b18d8f commit bae7301
Show file tree
Hide file tree
Showing 23 changed files with 1,261 additions and 138 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -52,7 +52,7 @@ repositories {
}

dependencies {
compile "mcp.mobius.waila:Waila:${waila_version}"
deobfCompile "mcp.mobius.waila:Waila:${waila_version}"
}

sourceSets {
Expand Down
Empty file modified gradlew 100644 → 100755
Empty file.
Binary file modified resources/assets/enderzoo/entity/owl.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 93 additions & 16 deletions src/main/java/crazypants/enderzoo/entity/EntityOwl.java
@@ -1,15 +1,12 @@
package crazypants.enderzoo.entity;

import crazypants.enderzoo.EnderZoo;
import crazypants.enderzoo.config.Config;
import crazypants.enderzoo.entity.ai.EntityAIFlyingAttackOnCollide;
import crazypants.enderzoo.entity.ai.EntityAIFlyingFindPerch;
import crazypants.enderzoo.entity.ai.EntityAIFlyingLand;
import crazypants.enderzoo.entity.ai.EntityAIFlyingPanic;
import crazypants.enderzoo.entity.ai.EntityAIFlyingShortWander;
import crazypants.enderzoo.entity.ai.EntityAINearestAttackableTargetBounded;
import crazypants.enderzoo.entity.navigate.FlyingMoveHelper;
import crazypants.enderzoo.entity.navigate.FlyingPathNavigate;
import info.loenwind.owlgen.IGene;
import info.loenwind.owlgen.IGenome;
import info.loenwind.owlgen.impl.Genome;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
Expand All @@ -32,13 +29,30 @@
import net.minecraft.pathfinding.PathNavigate;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import crazypants.enderzoo.EnderZoo;
import crazypants.enderzoo.config.Config;
import crazypants.enderzoo.entity.ai.EntityAIFlyingAttackOnCollide;
import crazypants.enderzoo.entity.ai.EntityAIFlyingFindPerch;
import crazypants.enderzoo.entity.ai.EntityAIFlyingLand;
import crazypants.enderzoo.entity.ai.EntityAIFlyingPanic;
import crazypants.enderzoo.entity.ai.EntityAIFlyingShortWander;
import crazypants.enderzoo.entity.ai.EntityAINearestAttackableTargetBounded;
import crazypants.enderzoo.entity.genes.OwlBeakColor;
import crazypants.enderzoo.entity.genes.OwlCoatColor;
import crazypants.enderzoo.entity.genes.OwlLegColor;
import crazypants.enderzoo.entity.genes.OwlShade;
import crazypants.enderzoo.entity.genes.OwlSize;
import crazypants.enderzoo.entity.navigate.FlyingMoveHelper;
import crazypants.enderzoo.entity.navigate.FlyingPathNavigate;

public class EntityOwl extends EntityAnimal implements IFlyingMob {

private static final int GENOME_ID = 13;
public static final String NAME = "Owl";
public static final int EGG_BG_COL = 0xC17949;
public static final int EGG_FG_COL = 0xFFDDC6;
Expand All @@ -62,9 +76,25 @@ public class EntityOwl extends EntityAnimal implements IFlyingMob {
private float climbRate = 0.25f;
private float turnRate = 30;

public int timeUntilNextEgg;;
public int timeUntilNextEgg;

public static final List<Class<? extends IGene>> genetemplate = new ArrayList<Class<? extends IGene>>();
private IGenome genome;
static {
genetemplate.add(OwlCoatColor.class); // body, tail
genetemplate.add(OwlCoatColor.class); // head
genetemplate.add(OwlCoatColor.class); // wings
genetemplate.add(OwlLegColor.class); /// legs, feet
genetemplate.add(OwlBeakColor.class); // beak
genetemplate.add(OwlSize.class);
genetemplate.add(OwlShade.class);
}

public EntityOwl(World worldIn) {
this(worldIn, true);
}

private EntityOwl(World worldIn, boolean makeGenome) {
super(worldIn);
setSize(0.4F, 0.85F);
stepHeight = 1.0F;
Expand All @@ -91,6 +121,30 @@ public EntityOwl(World worldIn) {
moveHelper = new FlyingMoveHelper(this);

timeUntilNextEgg = getNextLayingTime();

if (makeGenome) {
genome = new Genome(dataWatcher, GENOME_ID, genetemplate);
if (!worldObj.isRemote) {
/**
* Most random owls start their life with wings and heads matching their
* body coloring.
*/
List<IGene> genes0 = genome.getGenes0();
List<IGene> genes1 = genome.getGenes1();
List<IGene> genesE = genome.getGenesE();
if (Math.random() < 0.95) {
genes0.set(1, genes0.get(0));
genes1.set(1, genes1.get(0));
genesE.set(1, genesE.get(0));
}
if (Math.random() < 0.975) {
genes0.set(2, genes0.get(0));
genes1.set(2, genes1.get(0));
genesE.set(2, genesE.get(0));
}
}
genome.startSync();
}
}

@Override
Expand Down Expand Up @@ -118,6 +172,12 @@ public float getBlockPathWeight(BlockPos pos) {

@Override
public boolean interact(EntityPlayer playerIn) {
if (playerIn.capabilities.isCreativeMode) {
ItemStack stack = playerIn.inventory.getCurrentItem();
if (stack != null && stack.getItem() == Items.stick) {
playerIn.addChatMessage(new ChatComponentText("Genome: " + genome.getGenesE() + (worldObj.isRemote ? " on client" : " on server")));
}
}
return super.interact(playerIn);
// if (!super.interact(playerIn)) {
// if (!worldObj.isRemote) {
Expand Down Expand Up @@ -331,19 +391,18 @@ public int getTalkInterval() {

@Override
public void playLivingSound() {
String snd = getLivingSound();
if (snd == null) {
if (worldObj == null || worldObj.isRemote || worldObj.isDaytime() || getAttackTarget() != null) {
return;
}

if (worldObj != null && !worldObj.isRemote && (worldObj.isDaytime() || getAttackTarget() != null)) {
String snd = getLivingSound();
if (snd == null) {
return;
}

float volume = getSoundVolume() * Config.owlHootVolumeMult;
float pitch = 0.8f * getSoundPitch();
playSound(snd, volume, pitch);

}

@Override
Expand All @@ -367,7 +426,17 @@ protected String getDeathSound() {

@Override
public EntityOwl createChild(EntityAgeable ageable) {
return new EntityOwl(worldObj);
EntityOwl baby = new EntityOwl(worldObj, false);

if (ageable instanceof EntityOwl) {
EntityOwl otherOwl = (EntityOwl) ageable;
baby.genome = new Genome(baby.dataWatcher, GENOME_ID, this.genome, otherOwl.genome);
} else {
baby.genome = new Genome(baby.dataWatcher, GENOME_ID, genetemplate, this.genome);
}
baby.genome.startSync();

return baby;
}

@Override
Expand Down Expand Up @@ -411,12 +480,20 @@ public void readEntityFromNBT(NBTTagCompound tagCompund) {
if (tagCompund.hasKey("EggLayTime")) {
this.timeUntilNextEgg = tagCompund.getInteger("EggLayTime");
}
if (tagCompund.hasKey("genome")) {
genome.setData(tagCompund.getString("genome"));
}
}

@Override
public void writeEntityToNBT(NBTTagCompound tagCompound) {
super.writeEntityToNBT(tagCompound);
tagCompound.setInteger("EggLayTime", this.timeUntilNextEgg);
tagCompound.setString("genome", genome.getData());
}

public IGenome getGenome() {
return genome;
}

}
44 changes: 44 additions & 0 deletions src/main/java/crazypants/enderzoo/entity/genes/OwlBeakColor.java
@@ -0,0 +1,44 @@
package crazypants.enderzoo.entity.genes;

import info.loenwind.owlgen.IGene;
import info.loenwind.owlgen.IMutationProvider;
import info.loenwind.owlgen.IWeightedGene;
import info.loenwind.owlgen.impl.MutationProvider;

import java.util.List;

public enum OwlBeakColor implements IGene {
MEDIUM(10),
DARK(10),
BROWN(5),
GRAY(10),
BLACK(5);

private static final IMutationProvider mut = new MutationProvider();

static {
for (OwlBeakColor value : values()) {
mut.registerMutation(value, null, value, value.weight);
}
}

private final int weight;

private OwlBeakColor(int weight) {
this.weight = weight;
}

@Override
public List<IWeightedGene> getChildrenGenes() {
return mut.getChildrenGenes(this, null);
}

@Override
public List<IWeightedGene> getChildrenGenes(IGene partner) {
return mut.getChildrenGenes(this, partner);
}

public static int count() {
return values().length + 1;
}
}
64 changes: 64 additions & 0 deletions src/main/java/crazypants/enderzoo/entity/genes/OwlCoatColor.java
@@ -0,0 +1,64 @@
package crazypants.enderzoo.entity.genes;

import info.loenwind.owlgen.IGene;
import info.loenwind.owlgen.IMutationProvider;
import info.loenwind.owlgen.IWeightedGene;
import info.loenwind.owlgen.impl.MutationProvider;

import java.util.List;

public enum OwlCoatColor implements IGene {
LIGHT(10),
DARK(2),
GOLD(3),
WHITE(1);

private static final IMutationProvider mut = new MutationProvider();

static {
for (OwlCoatColor value : values()) {
mut.registerMutation(value, null, value, value.weight);
}
mut.registerMutation(LIGHT, DARK, DARK, 20);
mut.registerMutation(LIGHT, DARK, LIGHT, 100);
mut.registerMutation(LIGHT, DARK, GOLD, 1);

mut.registerMutation(LIGHT, GOLD, DARK, 20);
mut.registerMutation(LIGHT, GOLD, LIGHT, 100);
mut.registerMutation(LIGHT, GOLD, GOLD, 50);

mut.registerMutation(LIGHT, WHITE, LIGHT, 100);
mut.registerMutation(LIGHT, WHITE, WHITE, 10);

mut.registerMutation(DARK, GOLD, DARK, 50);
mut.registerMutation(DARK, GOLD, GOLD, 100);

mut.registerMutation(DARK, WHITE, LIGHT, 100);
mut.registerMutation(DARK, WHITE, DARK, 50);
mut.registerMutation(DARK, WHITE, WHITE, 50);

mut.registerMutation(GOLD, WHITE, WHITE, 50);
mut.registerMutation(GOLD, WHITE, GOLD, 50);
mut.registerMutation(GOLD, WHITE, LIGHT, 10);
}

private final int weight;

private OwlCoatColor(int weight) {
this.weight = weight;
}

@Override
public List<IWeightedGene> getChildrenGenes() {
return mut.getChildrenGenes(this, null);
}

@Override
public List<IWeightedGene> getChildrenGenes(IGene partner) {
return mut.getChildrenGenes(this, partner);
}

public static int count() {
return values().length + 1;
}
}
52 changes: 52 additions & 0 deletions src/main/java/crazypants/enderzoo/entity/genes/OwlLegColor.java
@@ -0,0 +1,52 @@
package crazypants.enderzoo.entity.genes;

import info.loenwind.owlgen.IGene;
import info.loenwind.owlgen.IMutationProvider;
import info.loenwind.owlgen.IWeightedGene;
import info.loenwind.owlgen.impl.MutationProvider;

import java.util.List;

public enum OwlLegColor implements IGene {
NORMAL(10),
BROWN(5),
RED(5),
GRAY(1),
BLACK(3);

private static final IMutationProvider mut = new MutationProvider();

static {
for (OwlLegColor value : values()) {
mut.registerMutation(value, null, value, value.weight);
}
mut.registerMutation(NORMAL, NORMAL, BROWN, 5);
mut.registerMutation(NORMAL, NORMAL, RED, 5);
mut.registerMutation(NORMAL, NORMAL, GRAY, 5);

mut.registerMutation(BROWN, BROWN, BLACK, 5);

mut.registerMutation(RED, GRAY, BROWN, 5);
mut.registerMutation(RED, GRAY, NORMAL, 5);
}

private final int weight;

private OwlLegColor(int weight) {
this.weight = weight;
}

@Override
public List<IWeightedGene> getChildrenGenes() {
return mut.getChildrenGenes(this, null);
}

@Override
public List<IWeightedGene> getChildrenGenes(IGene partner) {
return mut.getChildrenGenes(this, partner);
}

public static int count() {
return values().length + 1;
}
}

0 comments on commit bae7301

Please sign in to comment.