Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Imports that are required
- */
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.entity.projectile.EntityLargeFireball;
- import net.minecraft.entity.ai.EntityAIFindEntityNearestPlayer;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.network.datasync.DataParameter;
- import net.minecraft.network.datasync.DataSerializers;
- import net.minecraft.network.datasync.EntityDataManager;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.entity.ai.EntityAIWatchClosest;
- /**
- * AI tasks
- */
- this.tasks.addTask(4, new EntityCustom.AIFireballAttack(this));
- this.targetTasks.addTask(1, new EntityAIFindEntityNearestPlayer(this));
- /**
- * IMPORTANT: For some odd reason it uses same sound effect as Ghast when it's shotting but I don't see any relation to it here
- * unless the projectile will have it coded than, also Paste code below in space Between AILookAround code and AI Tasks
- */
- /**
- * This is here to determine if mob is in Idle or Attacking State
- */
- private static final DataParameter<Boolean> ATTACKING = EntityDataManager.<Boolean>createKey(EntityCustom.class, DataSerializers.BOOLEAN);
- /**
- * Strenght of projectile that is shooted
- */
- private int explosionStrength = 3;
- /**
- * Stuff to determine mob state
- */
- @SideOnly(Side.CLIENT)
- public boolean isAttacking()
- {
- return ((Boolean)this.dataManager.get(ATTACKING)).booleanValue();
- }
- public void setAttacking(boolean attacking)
- {
- this.dataManager.set(ATTACKING, Boolean.valueOf(attacking));
- }
- /**
- * Defines the variable that will contain strength of our projectile
- */
- public int getFireballStrength()
- {
- return this.explosionStrength;
- }
- /**
- * Sets Mob state from Attack to Idle when mob is Initialized
- */
- protected void entityInit()
- {
- super.entityInit();
- this.dataManager.register(ATTACKING, Boolean.valueOf(false));
- }
- /**
- * (abstract) Protected helper method to write subclass entity data to NBT.
- */
- public void writeEntityToNBT(NBTTagCompound compound)
- {
- super.writeEntityToNBT(compound);
- compound.setInteger("ExplosionPower", this.explosionStrength);
- }
- /**
- * (abstract) Protected helper method to read subclass entity data from NBT.
- */
- public void readEntityFromNBT(NBTTagCompound compound)
- {
- super.readEntityFromNBT(compound);
- if (compound.hasKey("ExplosionPower", 99))
- {
- this.explosionStrength = compound.getInteger("ExplosionPower");
- }
- }
- /**
- * The part that changes our mob into flying Airship with cannon
- * As usual EntityCustom is our Entity class name, boo stands for bariable
- */
- static class AIFireballAttack extends EntityAIBase
- {
- private final EntityCustom parentEntity;
- public int attackTimer;
- public AIFireballAttack(EntityCustom boo)
- {
- this.parentEntity = boo;
- }
- /**
- * Returns whether the EntityAIBase should begin execution.
- */
- public boolean shouldExecute()
- {
- return this.parentEntity.getAttackTarget() != null;
- }
- /**
- * Execute a one shot task or start executing a continuous task
- */
- public void startExecuting()
- {
- this.attackTimer = 0;
- }
- /**
- * Reset the task's internal state. Called when this task is interrupted by another one
- */
- public void resetTask()
- {
- this.parentEntity.setAttacking(false);
- }
- /**
- * Keep ticking a continuous task that has already been started
- */
- public void updateTask()
- {
- EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
- double d0 = 64.0D;
- if (entitylivingbase.getDistanceSq(this.parentEntity) < 4096.0D && this.parentEntity.canEntityBeSeen(entitylivingbase))
- {
- World world = this.parentEntity.world;
- ++this.attackTimer;
- if (this.attackTimer == 10)
- {
- world.playEvent((EntityPlayer)null, 1015, new BlockPos(this.parentEntity), 0);
- }
- /**
- * This part defines what projectile is shooted and from what X/Y/Z location of our mob Bounding Box
- * based on Eye's height "You can change projectile from Large Fireball to something else"
- */
- if (this.attackTimer == 20)
- {
- double d1 = 4.0D;
- Vec3d vec3d = this.parentEntity.getLook(2.0F);
- double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.x * 4.0D);
- double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
- double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.z * 4.0D);
- world.playEvent((EntityPlayer)null, 1016, new BlockPos(this.parentEntity), 0);
- EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
- entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
- entitylargefireball.posX = this.parentEntity.posX + vec3d.x * 4.0D;
- entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
- entitylargefireball.posZ = this.parentEntity.posZ + vec3d.z * 4.0D;
- world.spawnEntity(entitylargefireball);
- this.attackTimer = -40;
- }
- }
- else if (this.attackTimer > 0)
- {
- --this.attackTimer;
- }
- this.parentEntity.setAttacking(this.attackTimer > 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement