C’est bizarre je n’ai pas creer de variable rand pour mes Items.
package fr.hard.mod.Entity;
import fr.hard.mod.HSoundEvents;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
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.EntityCreeper;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntityPolarBear;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
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.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.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
public class EntityAssassin extends EntityMob
{
public static ItemStack equippedItems[];
public int currentItem; {
currentItem = rand.nextInt(equippedItems.length);}
public EntityAssassin(World worldIn)
{
super(worldIn);
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false));
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(8, new EntityAILookIdle(this));
this.applyEntityAI();
}
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(12.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.39000000417232513D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D);
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
}
protected void applyEntityAI()
{
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityPlayer.class}));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityBandit.class, false));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityCreeper.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityPirate.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityRogue.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityRogueArcher.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityShadow.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityZombie.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityCreeper.class, true));
}
protected SoundEvent getHurtSound()
{
return HSoundEvents.ENTITY_HURT;
}
protected SoundEvent getDeathSound()
{
return HSoundEvents.ENTITY_NEUTRAL_DEATH;
}
public void dropFewItems(boolean b, int looting)
{
this.dropItem(Items.GOLD_INGOT, 2);
this.dropItem(Items.REDSTONE, 1);
}
static
{
equippedItems = (new ItemStack[]
{
new ItemStack(Items.WOODEN_PICKAXE, 1), new ItemStack(Items.WOODEN_SWORD, 1), new ItemStack(Items.BRICK, 1), new ItemStack(Items.IRON_AXE, 1), new ItemStack(Items.GOLDEN_AXE, 1), new ItemStack(Items.IRON_HOE, 1), new ItemStack(Items.DIAMOND_SWORD, 1), new ItemStack(Items.IRON_SWORD, 1), new ItemStack(Items.GOLDEN_SWORD, 1), new ItemStack(Items.IRON_PICKAXE, 1)
});
}
public ItemStack getHeldItem()
{
return equippedItems[currentItem];
}
public void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
nbttagcompound.setInteger("equippedItem", currentItem);
super.writeEntityToNBT(nbttagcompound);;
}
public void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
currentItem = nbttagcompound.getInteger("equippedItem");
super.readEntityFromNBT(nbttagcompound);
}
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
{
livingdata = super.onInitialSpawn(difficulty, livingdata);
this.setEquipmentBasedOnDifficulty(difficulty);
return livingdata;
}
@Override
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
{
super.setEquipmentBasedOnDifficulty(difficulty);
this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, equippedItems[currentItem]);
}
}