Posted July 23, 201312 yr Hello all! I asked a question like this before, and I kind-of got an answer...Whenever my entity gets to half health, I want it to spawn two more entities, and then die. It does this about half way...if I damage it to half health, it does nothing. However, If I damage it to half health, and then relog, it dies and spawns a spider, but not a zombie. How can I "fix" this, so that the player doesn't have to relog, and spawn both the spider and a zombie? My code is below. package assets.betterdefense.entity; import java.util.UUID; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EnumCreatureAttribute; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIBreakDoor; 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.ai.attributes.AttributeModifier; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntitySpider; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import assets.betterdefense.common.BetterDefense; import assets.betterdefense.common.EntityAIBreakWood; public class EntityRiot_Zombie extends EntityMob { boolean spawnZombie = true; int spawnCooldown = 1; int spawnTimer = 5; private float heightOffset = -0.5F; /** ticks until heightOffset is randomized */ private int heightOffsetUpdateTime; private int field_70846_g; private static final ResourceLocation textureLocation = new ResourceLocation("betterdefense:Riot_Zombie.png"); private static final UUID field_110187_bq = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836"); private static final AttributeModifier field_110188_br = new AttributeModifier(field_110187_bq, "Baby speed boost", 0.5D, 1); public EntityRiot_Zombie(World par1World) { super(par1World); this.isImmuneToFire = true; this.canBreatheUnderwater(); this.stepHeight = 1.2F; this.getNavigator().setBreakDoors(true); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIBreakDoor(this)); this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1D, false)); this.tasks.addTask(3, new EntityAIAttackOnCollide(this, EntityVillager.class, 1D, true)); this.tasks.addTask(5, new EntityAIMoveThroughVillage(this, 1D, false)); this.tasks.addTask(6, new EntityAIWander(this, 1D)); this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(7, new EntityAILookIdle(this)); this.tasks.addTask(8, new EntityAIBreakWood(this)); this.tasks.addTask(9, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true)); } protected void func_110147_ax() { super.func_110147_ax(); // Max Health - default 20.0D - min 0.0D - max Double.MAX_VALUE this.func_110148_a(SharedMonsterAttributes.field_111267_a).func_111128_a(20.0D); // Follow Range - default 32.0D - min 0.0D - max 2048.0D this.func_110148_a(SharedMonsterAttributes.field_111265_b).func_111128_a(45.0D); // Knockback Resistance - default 0.0D - min 0.0D - max 1.0D this.func_110148_a(SharedMonsterAttributes.field_111266_c).func_111128_a(0.7D); // Movement Speed - default 0.699D - min 0.0D - max Double.MAX_VALUE this.func_110148_a(SharedMonsterAttributes.field_111263_d).func_111128_a(0.20000000417232513D); // Attack Damage - default 2.0D - min 0.0D - max Doubt.MAX_VALUE this.func_110148_a(SharedMonsterAttributes.field_111264_e).func_111128_a(2.0D); } protected ResourceLocation func_110775_a(Entity entity) { return textureLocation; } public boolean canBreatheUnderwater() { return true; } public int getTotalArmorValue() { int i = super.getTotalArmorValue() + 2; if (i > 20) { i = 20; } return i; } public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { if (par1DamageSource.isFireDamage()) { par2 = 0; } if (super.attackEntityFrom(par1DamageSource, par2)) { if (par1DamageSource.getEntity() != null) { Entity par1Entity = par1DamageSource.getEntity(); int j = 0; if (par1Entity instanceof EntityLiving) { j += EnchantmentHelper.getKnockbackModifier((EntityLiving) par1Entity, this); if (j > 0) { this.motionX /= 0.6D; this.motionZ /= 0.6D; this.addVelocity((double) (MathHelper.sin(par1Entity.rotationYaw * (float) Math.PI / 180.0F) * (float) j * 0.5F), -0.1D, (double) (-MathHelper.cos(par1Entity.rotationYaw * (float) Math.PI / 180.0F) * (float) j * 0.5F)); } } } if (this.func_110143_aJ() <= this.func_110138_aP() / 2.0F) { stage++; spawnZombie(); spawnReplacement(); this.setDead(); } return true; } return false; } private void spawnZombie() { int numSpawned = 0; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnZombie((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; } if (numSpawned >= 1) return; } public boolean trySpawnZombie(int x, int y, int z) { EntityZombie zombie1 = new EntityZombie(worldObj); zombie1.setPosition(x, y, z); { if (!worldObj.isRemote) worldObj.spawnEntityInWorld(zombie1); zombie1.spawnExplosionParticle(); return true; } } private void spawnReplacement() { int numSpawned = 0; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 1) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; if (trySpawnReplacement((int) this.posX, (int) this.posY, (int) this.posZ)) { numSpawned++; } if (numSpawned >= 2) return; } public boolean trySpawnReplacement(int x, int y, int z) { EntitySpider spider = new EntitySpider(worldObj); spider.setPosition(x, y, z); { if (!worldObj.isRemote) worldObj.spawnEntityInWorld(spider); spider.spawnExplosionParticle(); return true; } } //if (this.worldObj.rand.nextInt(90) == 0) public void initCreature() { if (this.worldObj.rand.nextInt(100) == 0) { this.setCurrentItemOrArmor(1, new ItemStack(BetterDefense.Boots)); } for (int i = 0; i < this.equipmentDropChances.length; ++i) { this.equipmentDropChances[i] = 0F; } } protected boolean isAIEnabled() { return true; } protected String getDecay() { return "townaura"; } public void onLivingUpdate() { for (int i = 0; i < 2; ++i) { this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); this.worldObj.playSoundAtEntity(attackingPlayer, "betterdefense:moan1", 1.0F, 1.0F); //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); } super.onLivingUpdate(); } public boolean attackEntityAsMob(Entity par1Entity) { boolean flag = super.attackEntityAsMob(par1Entity); if (flag && this.getHeldItem() == null && this.isBurning() && this.rand.nextFloat() < (float)this.worldObj.difficultySetting * 0.3F) { par1Entity.setFire(2 * this.worldObj.difficultySetting); } return flag; } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return "betterdefense:moan"; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.zombie.hurt"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.zombie.death"; } /** * Plays step sound at given x, y, z for the entity */ protected void playStepSound(int par1, int par2, int par3, int par4) { this.playSound("mob.zombie.step", 0.15F, 1.0F); } /** * Returns the item ID for the item the mob drops on death. */ protected int getDropItemId() { return Item.rottenFlesh.itemID; } /** * Get this Entity's EnumCreatureAttribute */ public EnumCreatureAttribute getCreatureAttribute() { return EnumCreatureAttribute.UNDEAD; } protected void dropRareDrop(int par1) { switch (this.rand.nextInt(3)) { case 0: this.dropItem(Item.diamond.itemID, 1); break; case 1: this.dropItem(BetterDefense.HISword.itemID, 1); break; case 2: this.dropItem(Item.ingotIron.itemID, 1); } } /* protected void addRandomArmor() { super.addRandomArmor(); super.canPickUpLoot(); this.setCurrentItemOrArmor(2, new ItemStack(BetterDefense.Legs)); if (this.rand.nextFloat() < (this.worldObj.difficultySetting == 3 ? 0.05F : 0.01F)) { int i = this.rand.nextInt(3); if (i == 0) { this.setCurrentItemOrArmor(0, new ItemStack(Item.swordIron)); } else { this.setCurrentItemOrArmor(0, new ItemStack(Item.shovelIron)); } } } */ public void setGrowingAge(int i) { } } Any help is appreciated, thanks for looking! I am the creator of "The Breakfast Mod". http://cache.gyazo.com/9f747cb0c5979bafb79bcd28e86c0f5b.png[/img]
July 24, 201312 yr Author Nobody knows how to help me? I am the creator of "The Breakfast Mod". http://cache.gyazo.com/9f747cb0c5979bafb79bcd28e86c0f5b.png[/img]
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.