/*******************************************************************************
* 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;
import java.util.Calendar;
import java.util.UUID;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIFleeSun;
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.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;
import com.shinoow.abyssalcraft.api.item.ACItems;
import com.shinoow.abyssalcraft.lib.ACConfig;
import com.shinoow.abyssalcraft.lib.ACLib;
import com.shinoow.abyssalcraft.lib.ACLoot;
public class EntitySkeletonGoliath extends EntityMob {
private static final UUID attackDamageBoostUUID = UUID.fromString("648D7064-6A60-4F59-8ABE-C2C23A6DD7A9");
private static final AttributeModifier attackDamageBoost = new AttributeModifier(attackDamageBoostUUID, "Halloween Attack Damage Boost", 5.0D, 0);
public EntitySkeletonGoliath(World par1World) {
super(par1World);
setSize(1.0F, 4.5F);
tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, true));
tasks.addTask(3, new EntityAIMoveTowardsRestriction(this, 1.0D));
tasks.addTask(4, new EntityAIWander(this, 1.0D));
tasks.addTask(5, new EntityAIFleeSun(this, 1.0D));
tasks.addTask(7, new EntityAILookIdle(this));
tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
tasks.addTask(7, new EntityAIWatchClosest(this, EntityAbyssalZombie.class, 8.0F));
tasks.addTask(7, new EntityAIWatchClosest(this, EntityZombie.class, 8.0F));
tasks.addTask(7, new EntityAIWatchClosest(this, EntityDepthsGhoul.class, 8.0F));
tasks.addTask(7, new EntityAIWatchClosest(this, EntitySkeleton.class, 8.0F));
tasks.addTask(7, new EntityAIWatchClosest(this, EntitySkeletonGoliath.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();
getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.3D);
getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
if(ACConfig.hardcoreMode){
getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(200.0D);
getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(40.0D);
} else {
getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(100.0D);
getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(20.0D);
}
}
@Override
public boolean attackEntityAsMob(Entity par1Entity)
{
if(ACConfig.hardcoreMode && par1Entity instanceof EntityPlayer)
par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this).setDamageBypassesArmor().setDamageIsAbsolute(), 3 * (float)(ACConfig.damageAmpl > 1.0D ? ACConfig.damageAmpl : 1));
return super.attackEntityAsMob(par1Entity);
}
@Override
protected float getSoundPitch()
{
return rand.nextFloat() - rand.nextFloat() * 0.2F + 0.6F;
}
@Override
protected SoundEvent getAmbientSound()
{
return SoundEvents.ENTITY_SKELETON_AMBIENT;
}
@Override
protected SoundEvent getHurtSound()
{
return SoundEvents.ENTITY_SKELETON_HURT;
}
@Override
protected SoundEvent getDeathSound()
{
return SoundEvents.ENTITY_SKELETON_DEATH;
}
@Override
protected void playStepSound(BlockPos pos, Block par4)
{
playSound(SoundEvents.ENTITY_SKELETON_STEP, 0.15F, 1.0F);
}
@Override
protected Item getDropItem()
{
return Items.BONE;
}
@Override
public ItemStack getHeldItem(EnumHand hand){
if(hand == EnumHand.MAIN_HAND)
return new ItemStack(ACItems.cudgel);
return super.getHeldItem(hand);
}
@Override
protected ResourceLocation getLootTable(){
return ACLoot.ENTITY_SKELETON_GOLIATH;
}
@Override
public EnumCreatureAttribute getCreatureAttribute()
{
return EnumCreatureAttribute.UNDEAD;
}
@Override
public void onLivingUpdate()
{
if (world.isDaytime() && !world.isRemote && world.provider.getDimension() != ACLib.abyssal_wasteland_id)
{
float f = getBrightness(1.0F);
if (f > 0.5F && rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && world.canSeeSky(new BlockPos(MathHelper.floor(posX), MathHelper.floor(posY), MathHelper.floor(posZ))))
{
boolean flag = true;
ItemStack var3 = getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (!var3.isEmpty())
{
if (var3.isItemStackDamageable())
{
var3.setItemDamage(var3.getItemDamage() + rand.nextInt(2));
if (var3.getItemDamage() >= var3.getMaxDamage())
{
renderBrokenItemStack(var3);
setItemStackToSlot(EntityEquipmentSlot.HEAD, ItemStack.EMPTY);
}
}
flag = false;
}
if (flag)
setFire(8);
}
}
super.onLivingUpdate();
}
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData par1EntityLivingData)
{
par1EntityLivingData = super.onInitialSpawn(difficulty, par1EntityLivingData);
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;
}
}
IAttributeInstance attribute = getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);
Calendar calendar = world.getCurrentDate();
attribute.removeModifier(attackDamageBoost);
if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31)
attribute.applyModifier(attackDamageBoost);
return par1EntityLivingData;
}
}