Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - package me.geometrically.prehistoric.entity.entities;
 - import com.dabigjoe.obsidianAPI.animation.wrapper.IEntityAnimated;
 - import com.google.common.base.Predicate;
 - import me.geometrically.prehistoric.block.PEBlocks;
 - import me.geometrically.prehistoric.entity.ai.EntityAIDinoMate;
 - import me.geometrically.prehistoric.entity.ai.EntityAIGuardNest;
 - import me.geometrically.prehistoric.entity.ai.animation.EntityAICall;
 - import me.geometrically.prehistoric.entity.ai.animation.EntityAIEat;
 - import me.geometrically.prehistoric.entity.ai.animation.EntityAIStartle;
 - import me.geometrically.prehistoric.entity.entities.dakotaraptor.EntityDakotaraptor;
 - import net.minecraft.block.Block;
 - import net.minecraft.entity.*;
 - import net.minecraft.entity.ai.*;
 - import net.minecraft.entity.passive.EntityAnimal;
 - import net.minecraft.entity.passive.EntityTameable;
 - import net.minecraft.entity.player.EntityPlayer;
 - import net.minecraft.init.Items;
 - import net.minecraft.item.ItemFood;
 - import net.minecraft.item.ItemStack;
 - import net.minecraft.util.DamageSource;
 - import net.minecraft.util.EnumHand;
 - import net.minecraft.util.math.BlockPos;
 - import net.minecraft.util.math.MathHelper;
 - import net.minecraft.world.World;
 - import javax.annotation.Nullable;
 - import java.util.List;
 - import java.util.Random;
 - public class EntityDinosaurTameable extends EntityTameable implements IEntityAnimated {
 - public BlockPos nestBlockPos;
 - public Block nest;
 - protected EntityAIEat aiEat;
 - protected EntityAIStartle aiStartle;
 - protected EntityAIWatchClosest aiWatchClosest;
 - protected EntityAICall aiCall;
 - public boolean running;
 - public boolean attacking;
 - private int counter = 0;
 - public EntityDinosaurTameable(World world) {
 - super(world);
 - }
 - @Override
 - protected void initEntityAI() {
 - this.aiSit = new EntityAISit(this);
 - this.aiWatchClosest = new EntityAIWatchClosest(this, EntityPlayer.class, 25.0F);
 - this.tasks.addTask(0, new EntityAISwimming(this));
 - this.tasks.addTask(4, new EntityAILeapAtTarget(this, 0.4F));
 - this.tasks.addTask(5, new EntityAIAttackMelee(this, 1.0D, true));
 - this.tasks.addTask(6, new EntityDinosaurTameable.EntityAIGuardNest(this, 15.0D, 1.0D));
 - this.tasks.addTask(7, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
 - this.tasks.addTask(9, new EntityAIWanderAvoidWater(this, 1.0D));
 - this.tasks.addTask(10, aiWatchClosest);
 - 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]));
 - }
 - @Override
 - public void onLivingUpdate() {
 - super.onLivingUpdate();
 - if (this.aiWatchClosest != null) {
 - if (this.aiWatchClosest.shouldExecute()) {
 - this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3500001192092896D);
 - this.running = true;
 - } else {
 - this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3000001192092896D);
 - this.running = false;
 - }
 - }
 - if (this.attacking) {
 - this.counter++;
 - if (this.counter >= 20) {
 - this.attacking = false;
 - }
 - } else {
 - this.attacking = false;
 - this.counter = 0;
 - }
 - if(!this.isInLove() && this.growingAge == 0){
 - if(this.getRNG().nextInt(1) == 0){
 - this.setInLove(null);
 - }
 - }
 - }
 - @Override
 - public boolean attackEntityFrom(DamageSource source, float amount) {
 - if (this.aiStartle != null) {
 - this.aiStartle.execute = true;
 - }
 - if (this.getHealth() < 20.0F && this.getHealth() + amount > 20.0F && !this.isTamed() && !this.isOwner((EntityLivingBase) source.getTrueSource())) {
 - if (this.aiCall != null) {
 - this.aiCall.execute = true;
 - if (source.getTrueSource() != null) {
 - double distance2 = 32.0D;
 - double d4 = -1.0D;
 - for (int i = 0; i < this.world.loadedEntityList.size(); ++i) {
 - Entity currE = (Entity) world.loadedEntityList.get(i);
 - if (currE instanceof EntityDakotaraptor && currE != this) {
 - double d5 = currE.getDistanceSq(this.posX, this.posY, this.posZ);
 - if ((distance2 < 0.0D || d5 < distance2 * distance2) && (d4 == -1.0D || d5 < d4)) {
 - d4 = d5;
 - if (source.getTrueSource() instanceof EntityLivingBase)
 - ((EntityDakotaraptor) currE).setAttackTarget((EntityLivingBase) source.getTrueSource());
 - }
 - }
 - }
 - }
 - }
 - }
 - return super.attackEntityFrom(source, amount);
 - }
 - @Override
 - public boolean attackEntityAsMob(Entity entityIn) {
 - this.attacking = true;
 - boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float) ((int) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));
 - if (flag) {
 - this.applyEnchantments(this, entityIn);
 - }
 - return flag;
 - }
 - @Override
 - public boolean processInteract(EntityPlayer player, EnumHand hand) {
 - ItemStack itemstack = player.getHeldItem(hand);
 - if (this.isTamed()) {
 - if (!itemstack.isEmpty()) {
 - if (itemstack.getItem() instanceof ItemFood) {
 - ItemFood itemfood = (ItemFood) itemstack.getItem();
 - if (itemfood.isWolfsFavoriteMeat()) {
 - if (this.aiEat != null) {
 - this.aiEat.execute = true;
 - }
 - if (!player.capabilities.isCreativeMode) {
 - itemstack.shrink(1);
 - }
 - this.heal((float) itemfood.getHealAmount(itemstack));
 - return true;
 - }
 - }
 - }
 - if (this.isOwner(player) && !this.world.isRemote && !this.isBreedingItem(itemstack)) {
 - this.aiSit.setSitting(!this.isSitting());
 - this.isJumping = false;
 - this.navigator.clearPathEntity();
 - this.setAttackTarget((EntityLivingBase) null);
 - }
 - } else if (itemstack.getItem() == Items.BONE && this.isBaby())
 - {
 - if (!player.capabilities.isCreativeMode)
 - {
 - itemstack.shrink(1);
 - }
 - if (!this.world.isRemote)
 - {
 - if (this.rand.nextInt(3) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, player))
 - {
 - this.setTamedBy(player);
 - this.navigator.clearPathEntity();
 - this.setAttackTarget((EntityLivingBase)null);
 - this.aiSit.setSitting(true);
 - this.setHealth(20.0F);
 - this.playTameEffect(true);
 - this.world.setEntityState(this, (byte)7);
 - }
 - else
 - {
 - this.playTameEffect(false);
 - this.world.setEntityState(this, (byte)6);
 - }
 - }
 - return true;
 - }
 - return super.processInteract(player, hand);
 - }
 - @Override
 - public EntityDinosaurTameable createChild(EntityAgeable ageable) {
 - return new EntityDinosaurTameable(this.world);
 - }
 - @Override
 - public boolean isMoving() {
 - return this.limbSwingAmount > 0.02F;
 - }
 - public boolean isBaby(){
 - return false;
 - }
 - @Override
 - public boolean isBreedingItem(ItemStack stack)
 - {
 - return false;
 - }
 - public class EntityAIDinoMate extends EntityAIBase {
 - private final EntityDinosaurTameable animal;
 - private final Class <? extends EntityDinosaurTameable> mateClass;
 - World world;
 - private EntityDinosaurTameable targetMate;
 - int spawnBabyDelay;
 - double moveSpeed;
 - public EntityAIDinoMate(EntityDinosaurTameable animal, double moveSpeed)
 - {
 - this.animal = animal;
 - this.world = animal.world;
 - this.mateClass = animal.getClass();
 - this.moveSpeed = moveSpeed;
 - this.setMutexBits(3);
 - }
 - /**
 - * Returns whether the EntityAIBase should begin execution.
 - */
 - public boolean shouldExecute()
 - {
 - if (!this.animal.isInLove())
 - {
 - return false;
 - }
 - else
 - {
 - this.targetMate = this.getNearbyMate();
 - return this.targetMate != null && !this.animal.isTamed();
 - }
 - }
 - /**
 - * Returns whether an in-progress EntityAIBase should continue executing
 - */
 - public boolean shouldContinueExecuting()
 - {
 - return this.targetMate.isEntityAlive() && this.targetMate.isInLove() && this.spawnBabyDelay < 60;
 - }
 - /**
 - * Reset the task's internal state. Called when this task is interrupted by another one
 - */
 - public void resetTask()
 - {
 - this.targetMate = null;
 - this.spawnBabyDelay = 0;
 - }
 - /**
 - * Keep ticking a continuous task that has already been started
 - */
 - public void updateTask()
 - {
 - this.animal.getLookHelper().setLookPositionWithEntity(this.targetMate, 10.0F, (float)this.animal.getVerticalFaceSpeed());
 - this.animal.getNavigator().tryMoveToEntityLiving(this.targetMate, this.moveSpeed);
 - ++this.spawnBabyDelay;
 - if (this.spawnBabyDelay >= 60 && this.animal.getDistanceSqToEntity(this.targetMate) < 9.0D)
 - {
 - this.spawnNestWithEggs();
 - }
 - }
 - /**
 - * Loops through nearby animals and finds another animal of the same type that can be mated with. Returns the first
 - * valid mate found.
 - */
 - private EntityDinosaurTameable getNearbyMate()
 - {
 - List<EntityDinosaurTameable> list = this.world.<EntityDinosaurTameable>getEntitiesWithinAABB(this.mateClass, this.animal.getEntityBoundingBox().grow(8.0D));
 - double d0 = Double.MAX_VALUE;
 - EntityDinosaurTameable entityanimal = null;
 - for (EntityDinosaurTameable entityanimal1 : list)
 - {
 - if (this.animal.canMateWith(entityanimal1) && this.animal.getDistanceSqToEntity(entityanimal1) < d0)
 - {
 - entityanimal = entityanimal1;
 - d0 = this.animal.getDistanceSqToEntity(entityanimal1);
 - }
 - }
 - return entityanimal;
 - }
 - private void spawnNestWithEggs(){
 - Block nest = PEBlocks.nest;
 - this.animal.nest = nest;
 - this.targetMate.nest = nest;
 - BlockPos entityPos = new BlockPos(this.animal.posX, this.animal.posY, this.animal.posZ);
 - this.animal.nestBlockPos = entityPos;
 - this.targetMate.nestBlockPos = entityPos;
 - double posX= entityPos.getX() + 0.5D;
 - double posY= entityPos.getY() + 0.1D;
 - double posZ= entityPos.getZ() + 0.5D;
 - world.destroyBlock(entityPos, false);
 - world.setBlockState(entityPos, nest.getDefaultState());
 - Random random = this.animal.getRNG();
 - int eggs = this.animal.getRNG().nextInt(3) + 4;
 - EntityEgg egg1 = new EntityEgg(this.world, this.animal.createChild(targetMate));
 - EntityEgg egg2 = new EntityEgg(this.world, this.animal.createChild(targetMate));
 - EntityEgg egg3 = new EntityEgg(this.world, this.animal.createChild(targetMate));
 - EntityEgg egg4 = new EntityEgg(this.world, this.animal.createChild(targetMate));
 - egg1.setPositionAndRotation(posX + 0.25D, posY, posZ, random.nextFloat(), 0.125F);
 - egg2.setPositionAndRotation(posX - 0.25D, posY, posZ, random.nextFloat(), 0.125F);
 - egg3.setPositionAndRotation(posX, posY , posZ - 0.25F, random.nextFloat(), 0.125F);
 - egg4.setPositionAndRotation(posX, posY, posZ + 0.25F, random.nextFloat(), 0.125F);
 - this.world.spawnEntity(egg1);
 - this.world.spawnEntity(egg2);
 - this.world.spawnEntity(egg3);
 - this.world.spawnEntity(egg4);
 - if(eggs >= 5){
 - EntityEgg egg5 = new EntityEgg(this.world, this.animal.createChild(targetMate));
 - egg5.setPositionAndRotation(posX + 0.1F, posY, posZ + 0.1F, random.nextFloat(), 0.125F);
 - this.world.spawnEntity(egg5);
 - }
 - if(eggs == 6){
 - EntityEgg egg6 = new EntityEgg(this.world, this.animal.createChild(targetMate));
 - egg6.setPositionAndRotation(posX - 0.1F, posY, posZ - 0.1F, random.nextFloat(), 0.125F);
 - this.world.spawnEntity(egg6);
 - }
 - this.animal.resetInLove();
 - this.targetMate.resetInLove();
 - this.animal.setGrowingAge(6000);
 - this.targetMate.setGrowingAge(6000);
 - }
 - }
 - public class EntityAIGuardNest extends EntityAIBase {
 - private EntityDinosaurTameable dinosaur;
 - World world;
 - private double speed;
 - private double distance;
 - public EntityAIGuardNest(EntityDinosaurTameable dinosaur, double distance ,double speed){
 - this.dinosaur = dinosaur;
 - this.world = this.dinosaur.world;
 - this.speed = speed;
 - this.distance = distance;
 - }
 - @Override
 - public boolean shouldExecute(){
 - return this.dinosaur.nest != null && !this.dinosaur.isTamed() && this.dinosaur.nestBlockPos != null;
 - }
 - @Override
 - public void updateTask(){
 - if(MathHelper.sqrt(this.dinosaur.getDistanceSq(this.dinosaur.nestBlockPos)) > this.distance){
 - System.out.println("test");
 - this.dinosaur.getNavigator().tryMoveToXYZ(this.dinosaur.nestBlockPos.getX(), this.dinosaur.nestBlockPos.getY(), this.dinosaur.nestBlockPos.getZ(), this.speed);
 - } else {
 - System.out.println("test2");
 - List<EntityLiving> list = this.dinosaur.world.<EntityLiving>getEntitiesWithinAABB(EntityLiving.class, this.dinosaur.nest.getDefaultState().getCollisionBoundingBox(this.world, this.dinosaur.nestBlockPos).grow(this.distance));
 - for (EntityLiving attacker : list)
 - {
 - if (!(attacker instanceof EntityEgg) && !(attacker.getClass() != this.dinosaur.getClass()) && MathHelper.sqrt(attacker.getDistanceSq(this.dinosaur.nestBlockPos)) < this.distance)
 - {
 - this.dinosaur.setAttackTarget(attacker);
 - break;
 - }
 - }
 - }
 - }
 - @Override
 - public boolean shouldContinueExecuting()
 - {
 - return this.dinosaur.nest != null;
 - }
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment