Jump to content

[SOLVED] Entity doesnt spawn with armor


Manslaughter777

Recommended Posts

All i want is for my entity to always spawn with armor. Tried addRandomArmor but doesnt work.

 

Entity class:

 

 

package com.manslaughter777.moondimension.entity;

import java.util.Random;

import com.manslaughter777.moondimension.Main;

import net.minecraft.block.Block;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
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.EntityMob;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeModContainer;

public class EntitySpaceman extends EntityMob {

public EntitySpaceman(World world) {
	super(world);
        
     this.getNavigator().setBreakDoors(true);
     this.tasks.addTask(0, new EntityAISwimming(this));
     this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
     this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true));
     this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
     this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
     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.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
     //this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));;
     
     this.setSize(0.6F, 1.8F);
     this.setCustomNameTag("Spaceman");
     this.setCanPickUpLoot(true);
     this.setAlwaysRenderNameTag(true);
  
}


@Override
protected void addRandomArmor()
    {
	this.setCurrentItemOrArmor(4, new ItemStack(Items.leather_helmet));
	this.setCurrentItemOrArmor(3, new ItemStack(Items.leather_chestplate));
	this.setCurrentItemOrArmor(2, new ItemStack(Items.leather_leggings));
	this.setCurrentItemOrArmor(1, new ItemStack(Items.leather_boots));
    }
    
    protected Item getDropItem()
    {
        return Main.powerstone;
    }
    
    /**
     * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
     * par2 - Level of Looting used to kill this mob.
     */
    protected void dropFewItems(boolean recentlyHit, int lootingLevel) {
    	Random ran = new Random();
    	
    	ItemStack ironSword = new ItemStack(Items.iron_sword);
    	ItemStack ironPickaxe = new ItemStack(Items.iron_pickaxe);
    	ItemStack moonHelmet = new ItemStack(Items.leather_helmet);
    	ItemStack moonChestplate = new ItemStack(Items.leather_chestplate);
    	ItemStack moonLeggings = new ItemStack(Items.leather_leggings);
    	ItemStack moonBoots = new ItemStack(Items.leather_boots);
    	
    	ironSword.setItemDamage(165 + ran.nextInt(40));	
    	ironPickaxe.setItemDamage(165 + ran.nextInt(40));
    	moonHelmet.setItemDamage(30 + ran.nextInt(10));
    	moonChestplate.setItemDamage(30 + ran.nextInt(10));
    	moonLeggings.setItemDamage(30 + ran.nextInt(10));
    	moonBoots.setItemDamage(30 + ran.nextInt(10));
    	
    	//drops
    	if(ran.nextInt(2) == 0) entityDropItem(ironSword, 1F);
    	if(ran.nextInt(2) == 0) entityDropItem(ironPickaxe, 1F);
    	if(ran.nextInt(2) == 0) entityDropItem(moonHelmet, 1F);
    	if(ran.nextInt(2) == 0) entityDropItem(moonChestplate, 1F);
    	if(ran.nextInt(2) == 0) entityDropItem(moonLeggings, 1F);
    	if(ran.nextInt(2) == 0) entityDropItem(moonBoots, 1F);
    	dropItem(Item.getItemFromBlock(Blocks.dirt), 10 + ran.nextInt(12));
    	dropItem(Item.getItemFromBlock(Main.regolith), 10 + ran.nextInt(12));
    	dropItem(Item.getItemFromBlock(Blocks.stone), 16 + ran.nextInt(25));
    	dropItem(Item.getItemFromBlock(Main.moonStone), 16 + ran.nextInt(25));
    	dropItem(Item.getItemFromBlock(Blocks.log), 3 + ran.nextInt(3));
    	dropItem(Item.getItemFromBlock(Blocks.planks), 10 + ran.nextInt(12));
    	dropItem(Item.getItemFromBlock(Blocks.crafting_table), ran.nextInt(2));
    	dropItem(Item.getItemFromBlock(Blocks.chest), ran.nextInt(2));
    	
    	dropItem(Items.iron_ingot, 2 + ran.nextInt(3));
    	dropItem(Items.string, 2 + ran.nextInt(3));
    	dropItem(Items.bucket, ran.nextInt(2));
    	dropItem(Items.stick, 3 + ran.nextInt(4));
    	dropItem(Main.powerstone, 2 + ran.nextInt();
    	dropItem(Items.bread, 2 + ran.nextInt(3));
    	dropItem(Items.cooked_porkchop, 2 + ran.nextInt(3));
    	dropItem(Items.potato, ran.nextInt(3));
    	dropItem(Items.carrot, ran.nextInt(3));		  	
    }
    
    protected void dropRareDrop(int p_70600_1_)
    {
        this.entityDropItem(new ItemStack(Main.moonCrystal), 0.0F);
    }
    
    /*
    protected String getLivingSound()
    {
        return "";
    } */

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    /*
    protected String getHurtSound()
    {
        return "";
    }
    */

    /**
     * Returns the sound this mob makes on death.
     */
    /*
    protected String getDeathSound()
    {
        return "";
    }
    */

    protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_)
    {
        this.playSound("mob.zombie.step", 0.15F, 1.0F);
    }

    /*
protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
    }
    */
    @Override
    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);
        
    }

protected boolean isAIEnabled()
    {
        return true;
    }

}


 

 

Link to comment
Share on other sites

You could just set the armor in the Constructor, instead of the random method. (Might work might not, might be a better way. Correct me if I;m wrong.)

Tried that but didnt work :( but here is something I found... I make the entity drop a leather chestplate on death but it sometimes drops 2, which means that it is dropping its "worn" armor aswell. So it seems that the entity HAS armor on but I can't see it. I will try adding diamond armor to it to see if it gets more stronger. Must be some rendering issue though...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.