/** * */ package cn.dawn47.mob.entity; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityFlying; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.monster.IMob; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.util.Vec3; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; import cn.annoreg.core.Registrant; import cn.annoreg.mc.RegEntity; import cn.dawn47.mob.client.render.RendererDemonSeed; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; /** * 恶魔种子实体。实际上直接抄了恶魂的代码。(你够 * @author WeathFolD * */ @Registrant @RegEntity @RegEntity.HasRender public class EntityDemonSeed extends EntityFlying implements IMob { @RegEntity.Render @SideOnly(Side.CLIENT) public static RendererDemonSeed renderer; public int courseChangeCooldown; public double waypointX; public double waypointY; public double waypointZ; private Entity targetedEntity; /** Cooldown time between target loss and new target aquirement. */ private int aggroCooldown; public int prevAttackCounter; public int attackCounter; /** The explosion radius of spawned fireballs. */ private static final String __OBFID = "CL_00001689"; public EntityDemonSeed(World world) { super(world); this.setSize(1.8F, 1.2F); this.experienceValue = 5; } @SideOnly(Side.CLIENT) public boolean func_110182_bF() { return this.dataWatcher.getWatchableObjectByte(16) != 0; } @Override protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(16, Byte.valueOf((byte)0)); } @Override protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D); } @Override protected void updateEntityActionState() { if (!this.worldObj.isRemote && this.worldObj.difficultySetting == EnumDifficulty.PEACEFUL) { this.setDead(); } this.despawnEntity(); this.prevAttackCounter = this.attackCounter; double d0 = this.waypointX - this.posX; double d1 = this.waypointY - this.posY; double d2 = this.waypointZ - this.posZ; double d3 = d0 * d0 + d1 * d1 + d2 * d2; if (d3 < 1.0D || d3 > 3600.0D) { this.waypointX = this.posX + ((this.rand.nextFloat() * 2.0F - 1.0F) * 7.0F - 3.5F); this.waypointY = this.posY + ((this.rand.nextFloat() * 2.0F - 1.0F) * 7.0F - 3.5F); this.waypointZ = this.posZ + ((this.rand.nextFloat() * 2.0F - 1.0F) * 7.0F - 3.5F); } if (this.courseChangeCooldown-- <= 0) { this.courseChangeCooldown += this.rand.nextInt(5) + 2; d3 = MathHelper.sqrt_double(d3); if (this.isCourseTraversable(this.waypointX, this.waypointY, this.waypointZ, d3)) { this.motionX += d0 / d3 * 0.1D; this.motionY += d1 / d3 * 0.1D; this.motionZ += d2 / d3 * 0.1D; } else { this.waypointX = this.posX; this.waypointY = this.posY; this.waypointZ = this.posZ; } } if (this.targetedEntity != null && this.targetedEntity.isDead) { this.targetedEntity = null; } if (this.targetedEntity == null || this.aggroCooldown-- <= 0) { this.targetedEntity = this.worldObj.getClosestVulnerablePlayerToEntity(this, 100.0D); if (this.targetedEntity != null) { this.aggroCooldown = 20; } } double d4 = 64.0D; if (this.targetedEntity != null && this.targetedEntity.getDistanceSqToEntity(this) < d4 * d4) { double d5 = this.targetedEntity.posX - this.posX; double d6 = this.targetedEntity.boundingBox.minY + this.targetedEntity.height / 2.0F - (this.posY + this.height / 2.0F); double d7 = this.targetedEntity.posZ - this.posZ; this.renderYawOffset = this.rotationYaw = -((float)Math.atan2(d5, d7)) * 180.0F / (float)Math.PI; if (this.canEntityBeSeen(this.targetedEntity)) { if (this.attackCounter == 10) { //this.playSound("dawn47:entities.attack", 0.5F, 1.0F); } ++this.attackCounter; if (this.attackCounter == 20) { this.playSound("dawn47:entities.attack", 0.5F, 1.0F); EntitySeedSpit spit = new EntitySeedSpit(this.worldObj, this, d5, d6, d7); // entitylargefireball.field_92057_e = this.explosionStrength; double d8 = 4.0D; Vec3 vec3 = this.getLook(1.0F); spit.posX = this.posX + vec3.xCoord * d8; spit.posY = this.posY + this.height / 2.0F + 0.5D; spit.posZ = this.posZ + vec3.zCoord * d8; this.worldObj.spawnEntityInWorld(spit); this.attackCounter = -40; } } else if (this.attackCounter > 0) { --this.attackCounter; } } else { this.renderYawOffset = this.rotationYaw = -((float)Math.atan2(this.motionX, this.motionZ)) * 180.0F / (float)Math.PI; if (this.attackCounter > 0) { --this.attackCounter; } } if (!this.worldObj.isRemote) { byte b1 = this.dataWatcher.getWatchableObjectByte(16); byte b0 = (byte)(this.attackCounter > 10 ? 1 : 0); if (b1 != b0) { this.dataWatcher.updateObject(16, Byte.valueOf(b0)); } } } /** * True if the ghast has an unobstructed line of travel to the waypoint. */ private boolean isCourseTraversable(double par1, double par3, double par5, double par7) { double d4 = (this.waypointX - this.posX) / par7; double d5 = (this.waypointY - this.posY) / par7; double d6 = (this.waypointZ - this.posZ) / par7; AxisAlignedBB axisalignedbb = this.boundingBox.copy(); for (int i = 1; i < par7; ++i) { axisalignedbb.offset(d4, d5, d6); if (!this.worldObj.getCollidingBoundingBoxes(this, axisalignedbb).isEmpty()) { return false; } } return true; } /** * Returns the sound this mob makes while it's alive. */ @Override protected String getLivingSound() { return "dawn47:entities.ds_howl"; } /** * Returns the sound this mob makes when it is hurt. */ @Override protected String getHurtSound() { return "dawn47:entities.ds_howl"; } /** * Returns the sound this mob makes on death. */ @Override protected String getDeathSound() { return "dawn47:entities.ds_death"; } /** * Returns the volume for the sounds this mob makes. */ @Override protected float getSoundVolume() { return 10.0F; } /** * Checks if the entity's current position is a valid location to spawn this entity. */ @Override public boolean getCanSpawnHere() { return this.rand.nextInt(20) == 0 && super.getCanSpawnHere() && this.worldObj.difficultySetting != EnumDifficulty.PEACEFUL; } /** * Will return how many at most can spawn in a chunk at once. */ @Override public int getMaxSpawnedInChunk() { return 32; } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ @Override public void writeEntityToNBT(NBTTagCompound tag) { super.writeEntityToNBT(tag); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ @Override public void readEntityFromNBT(NBTTagCompound tag) { super.readEntityFromNBT(tag); } }