-
-
Save JayZX535/2d642d0ca8a015e131646e3ee9b0650d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wildcraft.wildcraft.entity.canine; | |
import com.google.common.base.Predicate; | |
import com.wildcraft.wildcraft.WildCraft; | |
import com.wildcraft.wildcraft.client.gui.GuiHandler; | |
import com.wildcraft.wildcraft.entity.util.EntityWildCraft; | |
import com.wildcraft.wildcraft.entity.util.EntityWildCraftMammal; | |
import java.util.UUID; | |
import javax.annotation.Nullable; | |
import net.minecraft.block.Block; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityAgeable; | |
import net.minecraft.entity.EntityLiving; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.IEntityLivingData; | |
import net.minecraft.entity.SharedMonsterAttributes; | |
import net.minecraft.entity.ai.EntityAIAttackMelee; | |
import net.minecraft.entity.ai.EntityAIAvoidEntity; | |
import net.minecraft.entity.ai.EntityAIBeg; | |
import net.minecraft.entity.ai.EntityAIFollowOwner; | |
import net.minecraft.entity.ai.EntityAIHurtByTarget; | |
import net.minecraft.entity.ai.EntityAILeapAtTarget; | |
import net.minecraft.entity.ai.EntityAILookIdle; | |
import net.minecraft.entity.ai.EntityAIMate; | |
import net.minecraft.entity.ai.EntityAINearestAttackableTarget; | |
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget; | |
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget; | |
import net.minecraft.entity.ai.EntityAISit; | |
import net.minecraft.entity.ai.EntityAISwimming; | |
import net.minecraft.entity.ai.EntityAITargetNonTamed; | |
import net.minecraft.entity.ai.EntityAIWanderAvoidWater; | |
import net.minecraft.entity.ai.EntityAIWatchClosest; | |
import net.minecraft.entity.monster.AbstractSkeleton; | |
import net.minecraft.entity.monster.EntityCreeper; | |
import net.minecraft.entity.monster.EntityGhast; | |
import net.minecraft.entity.passive.AbstractHorse; | |
import net.minecraft.entity.passive.EntityAnimal; | |
import net.minecraft.entity.passive.EntityLlama; | |
import net.minecraft.entity.passive.EntityRabbit; | |
import net.minecraft.entity.passive.EntitySheep; | |
import net.minecraft.entity.passive.EntityTameable; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.projectile.EntityArrow; | |
import net.minecraft.init.Items; | |
import net.minecraft.init.SoundEvents; | |
import net.minecraft.inventory.ContainerHorseChest; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.item.EnumDyeColor; | |
import net.minecraft.item.ItemFood; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.network.datasync.DataParameter; | |
import net.minecraft.network.datasync.DataSerializers; | |
import net.minecraft.network.datasync.EntityDataManager; | |
import net.minecraft.util.DamageSource; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.util.EnumHand; | |
import net.minecraft.util.EnumParticleTypes; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraft.util.SoundEvent; | |
import net.minecraft.util.datafix.DataFixer; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.util.math.MathHelper; | |
import net.minecraft.world.DifficultyInstance; | |
import net.minecraft.world.World; | |
import net.minecraft.world.storage.loot.LootTableList; | |
import net.minecraftforge.common.capabilities.Capability; | |
import net.minecraftforge.common.capabilities.ICapabilityProvider; | |
import net.minecraftforge.fml.relauncher.Side; | |
import net.minecraftforge.fml.relauncher.SideOnly; | |
import net.minecraftforge.items.CapabilityItemHandler; | |
import net.minecraftforge.items.IItemHandler; | |
import net.minecraftforge.items.ItemStackHandler; | |
public class EntityWildCraftWolf extends EntityWildCraftMammal implements ICapabilityProvider | |
{ | |
private ItemStackHandler handler; | |
private static final DataParameter<Float> DATA_HEALTH_ID = EntityDataManager.<Float>createKey(EntityWildCraftWolf.class, DataSerializers.FLOAT); | |
private static final DataParameter<Boolean> BEGGING = EntityDataManager.<Boolean>createKey(EntityWildCraftWolf.class, DataSerializers.BOOLEAN); | |
private static final DataParameter<Float> SIZE = EntityDataManager.<Float>createKey(EntityWildCraftWolf.class, DataSerializers.FLOAT); | |
/** Float used to smooth the rotation of the wolf head */ | |
private float headRotationCourse; | |
private float headRotationCourseOld; | |
/** true is the wolf is wet else false */ | |
private boolean isWet; | |
/** True if the wolf is shaking else False */ | |
private boolean isShaking; | |
/** This time increases while wolf is shaking and emitting water particles. */ | |
private float timeWolfIsShaking; | |
private float prevTimeWolfIsShaking; | |
public EntityWildCraftWolf(World worldIn) | |
{ | |
super(worldIn); | |
this.setSize(0.6F, 0.85F); | |
this.setTamed(false); | |
this.setGenetics(this.randomizeGenetics()); | |
this.handler = new ItemStackHandler(11); | |
} | |
protected void initEntityAI() | |
{ | |
this.aiSit = new EntityAISit(this); | |
this.tasks.addTask(1, new EntityAISwimming(this)); | |
this.tasks.addTask(2, this.aiSit); | |
this.tasks.addTask(3, new EntityWildCraftWolf.AIAvoidEntity(this, EntityLlama.class, 24.0F, 1.5D, 1.5D)); | |
this.tasks.addTask(4, new EntityAILeapAtTarget(this, 0.4F)); | |
this.tasks.addTask(5, new EntityAIAttackMelee(this, 1.0D, true)); | |
this.tasks.addTask(6, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); | |
this.tasks.addTask(7, new EntityAIMate(this, 1.0D)); | |
this.tasks.addTask(8, new EntityAIWanderAvoidWater(this, 1.0D)); | |
//this.tasks.addTask(9, new EntityAIBeg(this, 8.0F)); | |
this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); | |
this.tasks.addTask(10, new EntityAILookIdle(this)); | |
this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); | |
this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); | |
this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true, new Class[0])); | |
this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityAnimal.class, false, new Predicate<Entity>() | |
{ | |
public boolean apply(@Nullable Entity p_apply_1_) | |
{ | |
return p_apply_1_ instanceof EntitySheep || p_apply_1_ instanceof EntityRabbit; | |
} | |
})); | |
this.targetTasks.addTask(5, new EntityAINearestAttackableTarget(this, AbstractSkeleton.class, false)); | |
} | |
protected void applyEntityAttributes() | |
{ | |
super.applyEntityAttributes(); | |
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.30000001192092896D); | |
if (this.isTamed()) | |
{ | |
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D); | |
} | |
else | |
{ | |
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(8.0D); | |
} | |
this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(2.0D); | |
} | |
/** | |
* Sets the active target the Task system uses for tracking | |
*/ | |
public void setAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn) | |
{ | |
super.setAttackTarget(entitylivingbaseIn); | |
if (entitylivingbaseIn == null) | |
{ | |
this.setAngry(false); | |
} | |
else if (!this.isTamed()) | |
{ | |
this.setAngry(true); | |
} | |
} | |
protected void updateAITasks() | |
{ | |
this.dataManager.set(DATA_HEALTH_ID, Float.valueOf(this.getHealth())); | |
} | |
protected void entityInit() | |
{ | |
super.entityInit(); | |
this.dataManager.register(DATA_HEALTH_ID, Float.valueOf(this.getHealth())); | |
this.dataManager.register(BEGGING, Boolean.valueOf(false)); | |
} | |
protected void playStepSound(BlockPos pos, Block blockIn) | |
{ | |
this.playSound(SoundEvents.ENTITY_WOLF_STEP, 0.15F, 1.0F); | |
} | |
public static void registerFixesWolf(DataFixer fixer) | |
{ | |
EntityLiving.registerFixesMob(fixer, EntityWildCraftWolf.class); | |
} | |
/** | |
* (abstract) Protected helper method to write subclass entity data to NBT. | |
*/ | |
public void writeEntityToNBT(NBTTagCompound compound) | |
{ | |
super.writeEntityToNBT(compound); | |
compound.setBoolean("Angry", this.isAngry()); | |
compound.setTag("ItemStackHandler", this.handler.serializeNBT()); | |
} | |
/** | |
* (abstract) Protected helper method to read subclass entity data from NBT. | |
*/ | |
public void readEntityFromNBT(NBTTagCompound compound) | |
{ | |
super.readEntityFromNBT(compound); | |
this.setAngry(compound.getBoolean("Angry")); | |
this.handler.deserializeNBT(compound.getCompoundTag("ItemStackHandler")); | |
} | |
protected SoundEvent getAmbientSound() | |
{ | |
return this.isAngry() ? SoundEvents.ENTITY_WOLF_GROWL : (this.rand.nextInt(3) == 0 ? (this.isTamed() && ((Float)this.dataManager.get(DATA_HEALTH_ID)).floatValue() < 10.0F ? SoundEvents.ENTITY_WOLF_WHINE : SoundEvents.ENTITY_WOLF_PANT) : SoundEvents.ENTITY_WOLF_AMBIENT); | |
} | |
protected SoundEvent getHurtSound() | |
{ | |
return SoundEvents.ENTITY_WOLF_HURT; | |
} | |
protected SoundEvent getDeathSound() | |
{ | |
return SoundEvents.ENTITY_WOLF_DEATH; | |
} | |
/** | |
* Returns the volume for the sounds this mob makes. | |
*/ | |
protected float getSoundVolume() | |
{ | |
return 0.4F; | |
} | |
@Nullable | |
protected ResourceLocation getLootTable() | |
{ | |
return LootTableList.ENTITIES_WOLF; | |
} | |
/** | |
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons | |
* use this to react to sunlight and start to burn. | |
*/ | |
public void onLivingUpdate() | |
{ | |
super.onLivingUpdate(); | |
if (!this.worldObj.isRemote && this.isWet && !this.isShaking && !this.hasPath() && this.onGround) | |
{ | |
this.isShaking = true; | |
this.timeWolfIsShaking = 0.0F; | |
this.prevTimeWolfIsShaking = 0.0F; | |
this.worldObj.setEntityState(this, (byte)8); | |
} | |
if (!this.worldObj.isRemote && this.getAttackTarget() == null && this.isAngry()) | |
{ | |
this.setAngry(false); | |
} | |
} | |
/** | |
* Called to update the entity's position/logic. | |
*/ | |
public void onUpdate() | |
{ | |
super.onUpdate(); | |
this.headRotationCourseOld = this.headRotationCourse; | |
if (this.isBegging()) | |
{ | |
this.headRotationCourse += (1.0F - this.headRotationCourse) * 0.4F; | |
} | |
else | |
{ | |
this.headRotationCourse += (0.0F - this.headRotationCourse) * 0.4F; | |
} | |
if (this.isWet()) | |
{ | |
this.isWet = true; | |
this.isShaking = false; | |
this.timeWolfIsShaking = 0.0F; | |
this.prevTimeWolfIsShaking = 0.0F; | |
} | |
else if ((this.isWet || this.isShaking) && this.isShaking) | |
{ | |
if (this.timeWolfIsShaking == 0.0F) | |
{ | |
this.playSound(SoundEvents.ENTITY_WOLF_SHAKE, this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); | |
} | |
this.prevTimeWolfIsShaking = this.timeWolfIsShaking; | |
this.timeWolfIsShaking += 0.05F; | |
if (this.prevTimeWolfIsShaking >= 2.0F) | |
{ | |
this.isWet = false; | |
this.isShaking = false; | |
this.prevTimeWolfIsShaking = 0.0F; | |
this.timeWolfIsShaking = 0.0F; | |
} | |
if (this.timeWolfIsShaking > 0.4F) | |
{ | |
float f = (float)this.getEntityBoundingBox().minY; | |
int i = (int)(MathHelper.sin((this.timeWolfIsShaking - 0.4F) * (float)Math.PI) * 7.0F); | |
for (int j = 0; j < i; ++j) | |
{ | |
float f1 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F; | |
float f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F; | |
this.worldObj.spawnParticle(EnumParticleTypes.WATER_SPLASH, this.posX + (double)f1, (double)(f + 0.8F), this.posZ + (double)f2, this.motionX, this.motionY, this.motionZ, new int[0]); | |
} | |
} | |
} | |
} | |
/** | |
* True if the wolf is wet | |
*/ | |
@SideOnly(Side.CLIENT) | |
public boolean isWolfWet() | |
{ | |
return this.isWet; | |
} | |
/** | |
* Used when calculating the amount of shading to apply while the wolf is wet. | |
*/ | |
@SideOnly(Side.CLIENT) | |
public float getShadingWhileWet(float p_70915_1_) | |
{ | |
return 0.75F + (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70915_1_) / 2.0F * 0.25F; | |
} | |
@SideOnly(Side.CLIENT) | |
public float getShakeAngle(float p_70923_1_, float p_70923_2_) | |
{ | |
float f = (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70923_1_ + p_70923_2_) / 1.8F; | |
if (f < 0.0F) | |
{ | |
f = 0.0F; | |
} | |
else if (f > 1.0F) | |
{ | |
f = 1.0F; | |
} | |
return MathHelper.sin(f * (float)Math.PI) * MathHelper.sin(f * (float)Math.PI * 11.0F) * 0.15F * (float)Math.PI; | |
} | |
@SideOnly(Side.CLIENT) | |
public float getInterestedAngle(float p_70917_1_) | |
{ | |
return (this.headRotationCourseOld + (this.headRotationCourse - this.headRotationCourseOld) * p_70917_1_) * 0.15F * (float)Math.PI; | |
} | |
public float getEyeHeight() | |
{ | |
return this.height * 0.8F; | |
} | |
/** | |
* The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently | |
* use in wolves. | |
*/ | |
public int getVerticalFaceSpeed() | |
{ | |
return this.isSitting() ? 20 : super.getVerticalFaceSpeed(); | |
} | |
/** | |
* Called when the entity is attacked. | |
*/ | |
public boolean attackEntityFrom(DamageSource source, float amount) | |
{ | |
if (this.isEntityInvulnerable(source)) | |
{ | |
return false; | |
} | |
else | |
{ | |
Entity entity = source.getEntity(); | |
if (this.aiSit != null) | |
{ | |
this.aiSit.setSitting(false); | |
} | |
if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow)) | |
{ | |
amount = (amount + 1.0F) / 2.0F; | |
} | |
return super.attackEntityFrom(source, amount); | |
} | |
} | |
public boolean attackEntityAsMob(Entity entityIn) | |
{ | |
boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float)((int)this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue())); | |
if (flag) | |
{ | |
this.applyEnchantments(this, entityIn); | |
} | |
return flag; | |
} | |
public void setTamed(boolean tamed) | |
{ | |
super.setTamed(tamed); | |
if (tamed) | |
{ | |
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D); | |
} | |
else | |
{ | |
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(8.0D); | |
} | |
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4.0D); | |
} | |
public boolean processInteract(EntityPlayer player, EnumHand hand) | |
{ | |
ItemStack itemstack = player.getHeldItem(hand); | |
if (this.isTamed()) | |
{ | |
if (!itemstack.func_190926_b()) | |
{ | |
if (itemstack.getItem() instanceof ItemFood) | |
{ | |
ItemFood itemfood = (ItemFood)itemstack.getItem(); | |
if (itemfood.isWolfsFavoriteMeat() && ((Float)this.dataManager.get(DATA_HEALTH_ID)).floatValue() < 20.0F) | |
{ | |
if (!player.capabilities.isCreativeMode) | |
{ | |
itemstack.func_190918_g(1); | |
} | |
this.heal((float)itemfood.getHealAmount(itemstack)); | |
return true; | |
} | |
} | |
} | |
if (this.isOwner(player) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) | |
{ | |
if (player.isSneaking()) | |
{ | |
if (!this.worldObj.isRemote) | |
{ | |
player.openGui(WildCraft.instance, GuiHandler.WOLF_INVENTORY, this.worldObj, this.getEntityId(), this.chunkCoordY, this.chunkCoordZ); | |
} | |
return true; | |
} | |
else | |
{ | |
this.aiSit.setSitting(!this.isSitting()); | |
this.isJumping = false; | |
this.navigator.clearPathEntity(); | |
this.setAttackTarget((EntityLivingBase)null); | |
} | |
} | |
} | |
else if (itemstack.getItem() == Items.BONE && !this.isAngry()) | |
{ | |
if (!player.capabilities.isCreativeMode) | |
{ | |
itemstack.func_190918_g(1); | |
} | |
if (!this.worldObj.isRemote) | |
{ | |
if (this.rand.nextInt(3) == 0) | |
{ | |
this.setTamed(true); | |
this.navigator.clearPathEntity(); | |
this.setAttackTarget((EntityLivingBase)null); | |
this.aiSit.setSitting(true); | |
this.setHealth(20.0F); | |
this.setOwnerId(player.getUniqueID()); | |
this.playTameEffect(true); | |
this.worldObj.setEntityState(this, (byte)7); | |
} | |
else | |
{ | |
this.playTameEffect(false); | |
this.worldObj.setEntityState(this, (byte)6); | |
} | |
} | |
return true; | |
} | |
return super.processInteract(player, hand); | |
} | |
@SideOnly(Side.CLIENT) | |
public void handleStatusUpdate(byte id) | |
{ | |
if (id == 8) | |
{ | |
this.isShaking = true; | |
this.timeWolfIsShaking = 0.0F; | |
this.prevTimeWolfIsShaking = 0.0F; | |
} | |
else | |
{ | |
super.handleStatusUpdate(id); | |
} | |
} | |
@SideOnly(Side.CLIENT) | |
public float getTailRotation() | |
{ | |
return this.isAngry() ? 1.5393804F : (this.isTamed() ? (0.55F - (this.getMaxHealth() - ((Float)this.dataManager.get(DATA_HEALTH_ID)).floatValue()) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F)); | |
} | |
/** | |
* Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on | |
* the animal type) | |
*/ | |
public boolean isBreedingItem(ItemStack stack) | |
{ | |
return stack.getItem() instanceof ItemFood && ((ItemFood)stack.getItem()).isWolfsFavoriteMeat(); | |
} | |
/** | |
* Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called | |
* when entity is reloaded from nbt. Mainly used for initializing attributes and inventory | |
*/ | |
@Nullable | |
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) | |
{ | |
livingdata = super.onInitialSpawn(difficulty, livingdata); | |
this.randomizeGenetics(); | |
boolean flag = false; | |
if (flag) | |
{ | |
this.setGrowingAge(-24000); | |
} | |
return livingdata; | |
} | |
private String randomizeGenetics() | |
{ | |
//Higher numbers = dominance (4 > 1) | |
String a = "22"; | |
String b = "11"; | |
String d = "11"; | |
String e = "11"; | |
String g = "00"; | |
String h = "00"; | |
String i = "00"; | |
String k = "00"; | |
String m = "00"; | |
String s = "22"; | |
String t = "00"; | |
String w = "00"; | |
int y; | |
int z; | |
//A locus: 3 = agouti, 2 = sable (wolf grey), 1 = tan points, 0 = recessive black | |
//B locus: 1 = black, 0 = liver | |
y = this.rand.nextInt(2); | |
z = this.rand.nextInt(2); | |
if (y == 1) | |
{ | |
if (z == 1) | |
{ | |
b = "00"; | |
} | |
else | |
{ | |
b = "10"; | |
} | |
} | |
else | |
{ | |
if (z == 1) | |
{ | |
b = "10"; | |
} | |
else | |
{ | |
b = "11"; | |
} | |
} | |
//D locus: 1 = normal, 0 = dilute | |
/**z = this.rand.nextInt(2); | |
if (z == 1) | |
{ | |
d = "10"; | |
} | |
else | |
{ | |
d = "11"; | |
}*/ | |
y = this.rand.nextInt(2); | |
z = this.rand.nextInt(2); | |
if (y == 1) | |
{ | |
if (z == 1) | |
{ | |
d = "00"; | |
} | |
else | |
{ | |
d = "10"; | |
} | |
} | |
else | |
{ | |
if (z == 1) | |
{ | |
d = "10"; | |
} | |
else | |
{ | |
d = "11"; | |
} | |
} | |
//E locus: 3 = masked, 2 = grizzle/domino, 1 = normal, 0 = recessive red | |
//G locus: 1 = greying, 0 = no greying | |
//H locus: 1 = harlequin, 0 = normal | |
//K locus: 2 = solid black, 1 = brindle, 0 = non-solid black | |
//M locus: 1 = merle, 0 = no merle | |
//S locus: 2 = no white, 1 = piebald, 0 = irish | |
//T locus: 2 = ticking, 1 = roan, 0 = no ticking | |
//W locus: 1 = no pure white override, 0 = pure white | |
y = this.rand.nextInt(5); | |
z = this.rand.nextInt(2); | |
if (y == 1) | |
{ | |
if (z == 1) | |
{ | |
w = "00"; | |
} | |
else | |
{ | |
w = "10"; | |
} | |
} | |
else | |
{ | |
if (z == 1) | |
{ | |
w = "10"; | |
} | |
else | |
{ | |
w = "11"; | |
} | |
} | |
//C locus | |
//VARIATIONS | |
//Intensity variation (Affects the intensity of color in a dog's coat, especially in red-- represented here by a scale of 1-5 with 1 being the palest. Offspring have a higher chance of inheriting a parent's intensity, but could inherit a random one) | |
//Pattern variation (chooses from different patterns. Offspring have a higher chance of inheriting a parent's pattern, but could inherit a random one) | |
//Eye variation (chooses from different eye intensities. Offspring have a higher chance of inheriting a parent's eye intensity, but could inherit a random one) | |
this.setGenetics(a+b+d+e+g+h+i+k+m+s+t+w); | |
System.out.println("DNA: " + this.getGenetics()); | |
System.out.println("DNA a: " + this.getGenetics().substring(22,24) ); | |
/**if (this.getGenetics().substring(22, 24).equals("00")) | |
{ | |
System.out.println("True"); | |
} | |
else | |
{ | |
System.out.println("False"); | |
}*/ | |
return (a+b+d+e+g+h+i+k+m+s+t+w); | |
} | |
/** | |
* Will return how many at most can spawn in a chunk at once. | |
*/ | |
public int getMaxSpawnedInChunk() | |
{ | |
return 8; | |
} | |
/** | |
* Determines whether this wolf is angry or not. | |
*/ | |
public boolean isAngry() | |
{ | |
return (((Byte)this.dataManager.get(TAMED)).byteValue() & 2) != 0; | |
} | |
/** | |
* Sets whether this wolf is angry or not. | |
*/ | |
public void setAngry(boolean angry) | |
{ | |
byte b0 = ((Byte)this.dataManager.get(TAMED)).byteValue(); | |
if (angry) | |
{ | |
this.dataManager.set(TAMED, Byte.valueOf((byte)(b0 | 2))); | |
} | |
else | |
{ | |
this.dataManager.set(TAMED, Byte.valueOf((byte)(b0 & -3))); | |
} | |
} | |
public EntityWildCraftWolf createChild(EntityAgeable ageable) | |
{ | |
EntityWildCraftWolf entitywolf = new EntityWildCraftWolf(this.worldObj); | |
UUID uuid = this.getOwnerId(); | |
if (uuid != null) | |
{ | |
entitywolf.setOwnerId(uuid); | |
entitywolf.setTamed(true); | |
} | |
return entitywolf; | |
} | |
public void setBegging(boolean beg) | |
{ | |
this.dataManager.set(BEGGING, Boolean.valueOf(beg)); | |
} | |
/** | |
* Returns true if the mob is currently able to mate with the specified mob. | |
*/ | |
public boolean canMateWith(EntityAnimal otherAnimal) | |
{ | |
if (otherAnimal == this) | |
{ | |
return false; | |
} | |
else if (!this.isTamed()) | |
{ | |
return false; | |
} | |
else if (!(otherAnimal instanceof EntityWildCraftWolf)) | |
{ | |
return false; | |
} | |
else | |
{ | |
EntityWildCraftWolf entitywolf = (EntityWildCraftWolf)otherAnimal; | |
return !entitywolf.isTamed() ? false : (entitywolf.isSitting() ? false : this.isInLove() && entitywolf.isInLove()); | |
} | |
} | |
public boolean isBegging() | |
{ | |
return ((Boolean)this.dataManager.get(BEGGING)).booleanValue(); | |
} | |
public boolean shouldAttackEntity(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) | |
{ | |
if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) | |
{ | |
if (p_142018_1_ instanceof EntityWildCraftWolf) | |
{ | |
EntityWildCraftWolf entitywolf = (EntityWildCraftWolf)p_142018_1_; | |
if (entitywolf.isTamed() && entitywolf.getOwner() == p_142018_2_) | |
{ | |
return false; | |
} | |
} | |
return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof AbstractHorse) || !((AbstractHorse)p_142018_1_).isTame(); | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
public boolean canBeLeashedTo(EntityPlayer player) | |
{ | |
return !this.isAngry() && super.canBeLeashedTo(player); | |
} | |
class AIAvoidEntity<T extends Entity> extends EntityAIAvoidEntity<T> | |
{ | |
private final EntityWildCraftWolf field_190856_d; | |
public AIAvoidEntity(EntityWildCraftWolf p_i47251_2_, Class<T> p_i47251_3_, float p_i47251_4_, double p_i47251_5_, double p_i47251_7_) | |
{ | |
super(p_i47251_2_, p_i47251_3_, p_i47251_4_, p_i47251_5_, p_i47251_7_); | |
this.field_190856_d = p_i47251_2_; | |
} | |
/** | |
* Returns whether the EntityAIBase should begin execution. | |
*/ | |
public boolean shouldExecute() | |
{ | |
return super.shouldExecute() && this.closestLivingEntity instanceof EntityLlama ? !this.field_190856_d.isTamed() && this.func_190854_a((EntityLlama)this.closestLivingEntity) : false; | |
} | |
private boolean func_190854_a(EntityLlama p_190854_1_) | |
{ | |
return p_190854_1_.func_190707_dL() >= EntityWildCraftWolf.this.rand.nextInt(5); | |
} | |
/** | |
* Execute a one shot task or start executing a continuous task | |
*/ | |
public void startExecuting() | |
{ | |
EntityWildCraftWolf.this.setAttackTarget((EntityLivingBase)null); | |
super.startExecuting(); | |
} | |
/** | |
* Updates the task | |
*/ | |
public void updateTask() | |
{ | |
EntityWildCraftWolf.this.setAttackTarget((EntityLivingBase)null); | |
super.updateTask(); | |
} | |
} | |
public void setBabyGenetics(EntityWildCraftWolf targetMate) { | |
int twins = this.rand.nextInt(10); | |
this.setBaby1Genetics(this.pickBabyGenetics(targetMate)); | |
if (twins == 1) | |
{ | |
this.setBaby2Genetics(this.pickBabyGenetics(targetMate)); | |
} | |
} | |
public String pickBabyGenetics(EntityWildCraftWolf father) | |
{ | |
String a = "22"; | |
String b = "11"; | |
String d = "11"; | |
String e = "11"; | |
String g = "00"; | |
String h = "00"; | |
String i = "00"; | |
String k = "00"; | |
String m = "00"; | |
String s = "22"; | |
String t = "00"; | |
String w = "00"; | |
int ssindex = 0; | |
int y = this.rand.nextInt(1); | |
int z = this.rand.nextInt(1); | |
//a | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
a = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
a = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
a = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
a = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//b | |
ssindex = 2; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
b = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
b = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
b = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
b = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//d | |
ssindex = 4; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
d = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
d = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
d = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
d = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//e | |
ssindex = 6; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
e = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
e = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
e = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
e = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//g | |
ssindex = 8; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
g = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
g = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
g = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
g = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//h | |
ssindex = 10; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
h = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
h = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
h = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
h = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//i | |
ssindex = 12; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
i = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
i = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
i = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
i = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//k | |
ssindex = 14; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
k = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
k = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
k = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
k = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//m | |
ssindex = 16; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
m = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
m = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
m = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
m = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//s | |
ssindex = 18; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
s = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
s = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
s = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
s = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//t | |
ssindex = 20; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
t = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
t = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
t = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
t = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
//w | |
ssindex = 22; | |
if (y == 0) | |
{ | |
if (z == 0) | |
{ | |
w = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
w = this.getGenetics().substring(ssindex, ssindex + 1) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
else | |
{ | |
if (z == 0) | |
{ | |
w = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex, ssindex + 1); | |
} | |
else | |
{ | |
w = this.getGenetics().substring(ssindex + 1, ssindex + 2) + father.getGenetics().substring(ssindex + 1, ssindex + 2); | |
} | |
} | |
return a+b+d+e+g+h+i+k+m+s+t+w; | |
} | |
/**public void openGUI(EntityPlayer playerEntity) | |
{ | |
if (!this.worldObj.isRemote && (!this.isBeingRidden() || this.isPassenger(playerEntity)) && this.isTame()) | |
{ | |
this.horseChest.setCustomName(this.getName()); | |
playerEntity.openGuiHorseInventory(this, this.horseChest); | |
} | |
}*/ | |
@Override | |
public <T> T getCapability(Capability<T> capability, EnumFacing facing) { | |
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) | |
{ | |
return (T) this.handler; | |
} | |
return super.getCapability(capability, facing); | |
} | |
@Override | |
public boolean hasCapability(Capability<?> capability, EnumFacing facing) { | |
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) | |
{ | |
return true; | |
} | |
return super.hasCapability(capability, facing); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment