Hello I am making a mod that adds Heroic Pigs. What I want to do is make it so when a new world is created one spawns right next to you already tamed and ready to protect you. How would I acheive this?
From what I can tell the code for setting its state is worldObj.setEntityState(this, (byte)7); but where do I put this? Hoepfully we can sort this out so we can all have a piggy to protect us one day. Please Help!
EntityCaptPig.java
package net.minecraft.src;
import java.util.Random;
public class EntityCaptPig extends EntityTameable
{
/**
* This flag is set when the wolf is looking at a player with interest, i.e. with tilted head. This happens when
* tamed wolf is wound and player holds porkchop (raw or cooked), or when wild wolf sees bone in player's hands.
*/
private boolean looksWithInterest;
private float field_25048_b;
private float field_25054_c;
private boolean isShaking;
private boolean field_25052_g;
/**
* This time increases while wolf is shaking and emitting water particles.
*/
private float timeWolfIsShaking;
private float prevTimeWolfIsShaking;
public EntityCaptPig(World par1World)
{
super(par1World);
looksWithInterest = false;
texture = "CaptPig.png";
setSize(0.6F, 0.8F);
moveSpeed = 0.3F;
func_48084_aL().func_48664_a(true);
tasks.addTask(1, new EntityAISwimming(this));
tasks.addTask(2, field_48146_a);
tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
tasks.addTask(4, new EntityAIAttackOnCollide(this, moveSpeed, true));
tasks.addTask(5, new EntityAIFollowOwner(this, moveSpeed, 10F, 2.0F));
tasks.addTask(6, new EntityAIMate(this, moveSpeed));
tasks.addTask(7, new EntityAIWander(this, moveSpeed));
tasks.addTask(8, new CaptPigAIBeg(this, 8F));
tasks.addTask(9, new EntityAIWatchClosest(this, net.minecraft.src.EntityPlayer.class, 8F));
tasks.addTask(9, new EntityAILookIdle(this));
field_48105_bU.addTask(1, new EntityAIOwnerHurtByTarget(this));
field_48105_bU.addTask(2, new EntityAIOwnerHurtTarget(this));
field_48105_bU.addTask(3, new EntityAIHurtByTarget(this, true));
field_48105_bU.addTask(4, new EntityAITargetNonTamed(this, net.minecraft.src.EntitySheep.class, 16F, 200, false));
}
/**
* Returns true if the newer Entity AI code should be run
*/
public boolean isAIEnabled()
{
return true;
}
public void func_48092_c(EntityLiving par1EntityLiving)
{
super.func_48092_c(par1EntityLiving);
if (par1EntityLiving instanceof EntityPlayer)
{
setAngry(true);
}
}
protected void func_48097_s_()
{
dataWatcher.updateObject(18, Integer.valueOf(getEntityHealth()));
}
public int getMaxHealth()
{
return !func_48139_F_() ? 8 : 20;
}
protected void entityInit()
{
super.entityInit();
dataWatcher.addObject(18, new Integer(getEntityHealth()));
}
/**
* returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
* prevent them from trampling crops
*/
protected boolean canTriggerWalking()
{
return false;
}
/**
* returns the directory and filename as a String
*/
public String getEntityTexture()
{
if (func_48139_F_())
{
return "CaptPig.png";
}
if (isAngry())
{
return "CaptPig.png";
}
else
{
return super.getEntityTexture();
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeEntityToNBT(par1NBTTagCompound);
par1NBTTagCompound.setBoolean("Angry", isAngry());
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readEntityFromNBT(par1NBTTagCompound);
setAngry(par1NBTTagCompound.getBoolean("Angry"));
}
/**
* Determines if an entity can be despawned, used on idle far away entities
*/
protected boolean canDespawn()
{
return isAngry();
}
/**
* Returns the sound this mob makes while it's alive.
*/
protected String getLivingSound()
{
if (isAngry())
{
return "mob.pig";
}
if (rand.nextInt(3) == 0)
{
if (func_48139_F_() && dataWatcher.getWatchableObjectInt(18) < 10)
{
return "mob.pig";
}
else
{
return "mob.pig";
}
}
else
{
return "mob.pig";
}
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mob.pig.hurt";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mob.pig.death";
}
/**
* Returns the volume for the sounds this mob makes.
*/
protected float getSoundVolume()
{
return 0.4F;
}
/**
* Returns the item ID for the item the mob drops on death.
*/
protected int getDropItemId()
{
return -1;
}
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate()
{
super.onLivingUpdate();
if (!worldObj.isRemote && isShaking && !field_25052_g && !hasPath() && onGround)
{
field_25052_g = true;
timeWolfIsShaking = 0.0F;
prevTimeWolfIsShaking = 0.0F;
worldObj.setEntityState(this, (byte)8);
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
field_25054_c = field_25048_b;
if (looksWithInterest)
{
field_25048_b = field_25048_b + (1.0F - field_25048_B) * 0.4F;
}
else
{
field_25048_b = field_25048_b + (0.0F - field_25048_B) * 0.4F;
}
if (looksWithInterest)
{
numTicksToChaseTarget = 10;
}
if (isWet())
{
isShaking = true;
field_25052_g = false;
timeWolfIsShaking = 0.0F;
prevTimeWolfIsShaking = 0.0F;
}
else if ((isShaking || field_25052_g) && field_25052_g)
{
if (timeWolfIsShaking == 0.0F)
{
worldObj.playSoundAtEntity(this, "mob.wolf.shake", getSoundVolume(), (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
}
prevTimeWolfIsShaking = timeWolfIsShaking;
timeWolfIsShaking += 0.05F;
if (prevTimeWolfIsShaking >= 2.0F)
{
isShaking = false;
field_25052_g = false;
prevTimeWolfIsShaking = 0.0F;
timeWolfIsShaking = 0.0F;
}
if (timeWolfIsShaking > 0.4F)
{
float f = (float)boundingBox.minY;
int i = (int)(MathHelper.sin((timeWolfIsShaking - 0.4F) * (float)Math.PI) * 7F);
for (int j = 0; j < i; j++)
{
float f1 = (rand.nextFloat() * 2.0F - 1.0F) * width * 0.5F;
float f2 = (rand.nextFloat() * 2.0F - 1.0F) * width * 0.5F;
worldObj.spawnParticle("splash", posX + (double)f1, f + 0.8F, posZ + (double)f2, motionX, motionY, motionZ);
}
}
}
}
public boolean getWolfShaking()
{
return isShaking;
}
/**
* Used when calculating the amount of shading to apply while the wolf is shaking.
*/
public float getShadingWhileShaking(float par1)
{
return 0.75F + ((prevTimeWolfIsShaking + (timeWolfIsShaking - prevTimeWolfIsShaking) * par1) / 2.0F) * 0.25F;
}
public float getShakeAngle(float par1, float par2)
{
float f = (prevTimeWolfIsShaking + (timeWolfIsShaking - prevTimeWolfIsShaking) * par1 + par2) / 1.8F;
if (f < 0.0F)
{
f = 0.0F;
}
else if (f > 1.0F)
{
f = 1.0F;
}
return MathHelper.sin(f * (float)Math.PI) * MathHelper.sin(f * (float)Math.PI * 11F) * 0.15F * (float)Math.PI;
}
public float getInterestedAngle(float par1)
{
return (field_25054_c + (field_25048_b - field_25054_c) * par1) * 0.15F * (float)Math.PI;
}
public float getEyeHeight()
{
return height * 0.8F;
}
/**
* The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently
* use in wolves.
*/
public int getVerticalFaceSpeed()
{
if (func_48141_af())
{
return 20;
}
else
{
return super.getVerticalFaceSpeed();
}
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
Entity entity = par1DamageSource.getEntity();
field_48146_a.func_48407_a(false);
if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
{
par2 = (par2 + 1) / 2;
}
return super.attackEntityFrom(par1DamageSource, par2);
}
public boolean attackEntityAsMob(Entity par1Entity)
{
byte byte0 = ((byte)(func_48139_F_() ? 4 : 2));
return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), byte0);
}
/**
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
*/
public boolean interact(EntityPlayer par1EntityPlayer)
{
ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
if (!func_48139_F_())
{
if (itemstack != null && itemstack.itemID == Item.bone.shiftedIndex && !isAngry())
{
itemstack.stackSize--;
if (itemstack.stackSize <= 0)
{
par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
}
if (!worldObj.isRemote)
{
if (rand.nextInt(3) == 0)
{
func_48138_b(true);
setPathToEntity(null);
func_48092_c(null);
field_48146_a.func_48407_a(true);
setEntityHealth(300);
func_48143_a(par1EntityPlayer.username);
func_48142_a(true);
worldObj.setEntityState(this, (byte)7);
}
else
{
func_48142_a(false);
worldObj.setEntityState(this, (byte)6);
}
}
return true;
}
}
else
{
if (itemstack != null && (Item.itemsList[itemstack.itemID] instanceof ItemFood))
{
ItemFood itemfood = (ItemFood)Item.itemsList[itemstack.itemID];
if (itemfood.isWolfsFavoriteMeat() && dataWatcher.getWatchableObjectInt(18) < 20)
{
itemstack.stackSize--;
heal(itemfood.getHealAmount());
if (itemstack.stackSize <= 0)
{
par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
}
return true;
}
}
if (par1EntityPlayer.username.equalsIgnoreCase(func_48145_ag()) && !worldObj.isRemote && !isWheat(itemstack))
{
field_48146_a.func_48407_a(!func_48141_af());
isJumping = false;
setPathToEntity(null);
}
}
return super.interact(par1EntityPlayer);
}
public void handleHealthUpdate(byte par1)
{
if (par1 == 8)
{
field_25052_g = true;
timeWolfIsShaking = 0.0F;
prevTimeWolfIsShaking = 0.0F;
}
else
{
super.handleHealthUpdate(par1);
}
}
public float setTailRotation()
{
if (isAngry())
{
return 1.53938F;
}
if (func_48139_F_())
{
return (0.55F - (float)(20 - dataWatcher.getWatchableObjectInt(18)) * 0.02F) * (float)Math.PI;
}
else
{
return ((float)Math.PI / 5F);
}
}
/**
* Checks if the parameter is an wheat item.
*/
public boolean isWheat(ItemStack par1ItemStack)
{
if (par1ItemStack == null)
{
return false;
}
if (!(Item.itemsList[par1ItemStack.itemID] instanceof ItemFood))
{
return false;
}
else
{
return ((ItemFood)Item.itemsList[par1ItemStack.itemID]).isWolfsFavoriteMeat();
}
}
/**
* Will return how many at most can spawn in a chunk at once.
*/
public int getMaxSpawnedInChunk()
{
return 8;
}
/**
* gets this wolf's angry state
*/
public boolean isAngry()
{
return (dataWatcher.getWatchableObjectByte(16) & 2) != 0;
}
/**
* sets this wolf's angry state to true if the boolean argument is true
*/
public void setAngry(boolean par1)
{
byte byte0 = dataWatcher.getWatchableObjectByte(16);
if (par1)
{
dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 | 2)));
}
else
{
dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 & -3)));
}
}
/**
* [This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.]
*/
public EntityAnimal spawnBabyAnimal(EntityAnimal par1EntityAnimal)
{
EntityWolf entitywolf = new EntityWolf(worldObj);
entitywolf.func_48143_a(func_48145_ag());
entitywolf.func_48138_b(true);
return entitywolf;
}
public void func_48150_h(boolean par1)
{
looksWithInterest = par1;
}
public boolean func_48135_b(EntityAnimal par1EntityAnimal)
{
if (par1EntityAnimal == this)
{
return false;
}
if (!func_48139_F_())
{
return false;
}
if (!(par1EntityAnimal instanceof EntityWolf))
{
return false;
}
EntityWolf entitywolf = (EntityWolf)par1EntityAnimal;
if (!entitywolf.func_48139_F_())
{
return false;
}
if (entitywolf.func_48141_af())
{
return false;
}
else
{
return func_48136_o_() && entitywolf.func_48136_o_();
}
}
}
mod_HeroPigs.java
package net.minecraft.src;
import java.util.Random;
import java.util.Map;
public class mod_HeroPigs extends BaseMod
{
public mod_HeroPigs()
{
AddMobs();
}
public void AddMobs()
{
ModLoader.registerEntityID(EntityCaptPig.class, "CaptPig", ModLoader.getUniqueEntityId(),0xFFFFFF, 0x003366);
ModLoader.addSpawn(EntityCaptPig.class, 500, 10, 10, EnumCreatureType.creature);
ModLoader.registerEntityID(EntitySpiderPig.class, "SpiderPig", ModLoader.getUniqueEntityId(),0xCC0000, 0x003366);
ModLoader.addSpawn(EntitySpiderPig.class, 10, 10, 10, EnumCreatureType.creature);
ModLoader.registerEntityID(EntityIronPig.class, "IronPig", ModLoader.getUniqueEntityId(),0xFFCC33 ,0xFF3300);
ModLoader.addSpawn(EntityIronPig.class, 10, 10, 10, EnumCreatureType.creature);
ModLoader.registerEntityID(EntityBatPig.class, "BatPig", ModLoader.getUniqueEntityId(),0x333333, 0xFFFC33);
ModLoader.addSpawn(EntityBatPig.class, 10, 20, 20, EnumCreatureType.creature);
ModLoader.addLocalization("entity.BatPig.name", "BatPig");
ModLoader.addLocalization("entity.IronPig.name", "IronPig");
ModLoader.addLocalization("entity.SpiderPig.name", "SpiderPig");
ModLoader.addLocalization("entity.CaptPig.name", "CaptainAmeriPig");
}
public void addRenderer(Map map) {
map.put(EntityCaptPig.class, new RenderCaptPig(new ModelCaptPig(), 0.5F));
map.put(EntitySpiderPig.class, new RenderSpiderPig(new ModelSpiderPig(), 0.5F));
map.put(EntityIronPig.class, new RenderIronPig(new ModelIronPig(), 0.5F));
map.put(EntityBatPig.class, new RenderBatPig(new ModelBatPig(), 5F));
}
public void load()
{
}
public String getVersion()
{
return "HeroicPigsMod 1.2.3";
}
}
From what I can tell the code for setting its state is worldObj.setEntityState(this, (byte)7); but where do I put this? Hoepfully we can sort this out so we can all have a piggy to protect us one day. Please Help!
EntityCaptPig.java
mod_HeroPigs.java