/*******************************************************************************
* AbyssalCraft
* Copyright (c) 2012 - 2017 Shinoow.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Contributors:
* Shinoow - implementation
******************************************************************************/
package com.shinoow.abyssalcraft.common.entity.anti;
import java.util.Calendar;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
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.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;
import com.shinoow.abyssalcraft.api.entity.IAntiEntity;
import com.shinoow.abyssalcraft.lib.ACConfig;
import com.shinoow.abyssalcraft.lib.ACLoot;
public class EntityAntiPlayer extends EntityMob implements IAntiEntity {
public EntityAntiPlayer(World par1World) {
super(par1World);
tasks.addTask(0, new EntityAISwimming(this));
tasks.addTask(2, new EntityAIAttackMelee(this, 0.35D, true));
tasks.addTask(3, new EntityAIMoveTowardsRestriction(this, 0.35D));
tasks.addTask(4, new EntityAIWander(this, 0.35D));
tasks.addTask(5, new EntityAILookIdle(this));
tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
}
@Override
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
if(ACConfig.hardcoreMode){
getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(80.0D);
getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4.0D);
} else
getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D);
}
@Override
public boolean attackEntityAsMob(Entity par1Entity)
{
if(ACConfig.hardcoreMode && par1Entity instanceof EntityPlayer)
par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this).setDamageBypassesArmor().setDamageIsAbsolute(), 1.5F * (float)(ACConfig.damageAmpl > 1.0D ? ACConfig.damageAmpl : 1));
return super.attackEntityAsMob(par1Entity);
}
@Override
public boolean canDespawn(){
return false;
}
@Override
protected void playStepSound(BlockPos pos, Block par4)
{
playSound(SoundEvents.ENTITY_ZOMBIE_STEP, 0.15F, 1.0F);
}
@Override
protected ResourceLocation getLootTable(){
return ACLoot.ENTITY_ANTI_PLAYER;
}
@Override
public void onKillEntity(EntityLivingBase par1EntityLivingBase)
{
super.onKillEntity(par1EntityLivingBase);
if (par1EntityLivingBase instanceof EntityPlayer)
{
if (rand.nextBoolean())
return;
EntityAntiPlayer antiPlayer = new EntityAntiPlayer(world);
antiPlayer.copyLocationAndAnglesFrom(par1EntityLivingBase);
world.removeEntity(par1EntityLivingBase);
antiPlayer.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(posX, posY, posZ)), (IEntityLivingData)null);
world.spawnEntity(antiPlayer);
world.playEvent((EntityPlayer)null, 1016, new BlockPos(posX, posY, posZ), 0);
}
}
@Override
protected void collideWithEntity(Entity par1Entity)
{
if(!world.isRemote && par1Entity instanceof EntityPlayer && ACConfig.hardcoreMode){
boolean flag = world.getGameRules().getBoolean("mobGriefing");
world.createExplosion(this, posX, posY, posZ, 5, flag);
setDead();
}
else par1Entity.applyEntityCollision(this);
}
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData par1EntityLivingData)
{
par1EntityLivingData = super.onInitialSpawn(difficulty, par1EntityLivingData);
setCanPickUpLoot(true);
setEquipmentBasedOnDifficulty(difficulty);
setEnchantmentBasedOnDifficulty(difficulty);
if (getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty())
{
Calendar calendar = world.getCurrentDate();
if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31 && rand.nextFloat() < 0.25F)
{
setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(rand.nextFloat() < 0.1F ? Blocks.LIT_PUMPKIN : Blocks.PUMPKIN));
inventoryArmorDropChances[EntityEquipmentSlot.HEAD.getIndex()] = 0.0F;
}
}
return par1EntityLivingData;
}
}