Advertisement
Guest User

entitypegasus

a guest
Jul 2nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. package com.ChaoticSoul.MoreArmor.entity;
  2.  
  3. import java.util.Set;
  4.  
  5. import com.ChaoticSoul.MoreArmor.init.ModItems;
  6. import com.google.common.collect.Sets;
  7.  
  8. import net.minecraft.entity.EntityLiving;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.IRangedAttackMob;
  11. import net.minecraft.entity.SharedMonsterAttributes;
  12. import net.minecraft.entity.ai.EntityAIAttackRanged;
  13. import net.minecraft.entity.ai.EntityAIAttackRangedBow;
  14. import net.minecraft.entity.ai.EntityAIFollow;
  15. import net.minecraft.entity.ai.EntityAIFollowOwnerFlying;
  16. import net.minecraft.entity.ai.EntityAILookIdle;
  17. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  18. import net.minecraft.entity.ai.EntityAISit;
  19. import net.minecraft.entity.ai.EntityAIWatchClosest;
  20. import net.minecraft.entity.monster.EntitySkeleton;
  21. import net.minecraft.entity.monster.IMob;
  22. import net.minecraft.entity.passive.EntityParrot;
  23. import net.minecraft.entity.player.EntityPlayer;
  24. import net.minecraft.entity.projectile.EntityTippedArrow;
  25. import net.minecraft.init.MobEffects;
  26. import net.minecraft.init.SoundEvents;
  27. import net.minecraft.item.Item;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.potion.Potion;
  30. import net.minecraft.potion.PotionEffect;
  31. import net.minecraft.util.DamageSource;
  32. import net.minecraft.util.EnumHand;
  33. import net.minecraft.util.math.MathHelper;
  34. import net.minecraft.world.World;
  35.  
  36. public class EntityPegasus extends EntityParrot implements IRangedAttackMob{
  37.  
  38. private final EntityAIAttackRangedBow<EntityPegasus> aiArrowAttack = new EntityAIAttackRangedBow<EntityPegasus>(this, 1.0D, 20, 15.0F);
  39. public EntityPegasus(World worldIn) {
  40.  
  41. super(worldIn);
  42.  
  43.  
  44. }
  45. protected void applyEntityAttributes()
  46. {
  47. super.applyEntityAttributes();
  48.  
  49.  
  50. this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20.0D);
  51. this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(6);
  52. this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.20000000298023224D);
  53.  
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. protected void initEntityAI()
  64. {
  65. this.tasks.addTask(1, new EntityAIFollowOwnerFlying(this, 2.0D, 5.0F, 1.0F));
  66. this.tasks.addTask(1, new EntityAISit(this));
  67. this.tasks.addTask(1, new EntityAIAttackRanged(this, 1.25D, 10, 10.0F));
  68. this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
  69. this.tasks.addTask(4, new EntityAILookIdle(this));
  70. this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityLiving.class, 10, true, false, IMob.MOB_SELECTOR));
  71. this.tasks.addTask(1, new EntityAIFollow(this, 2.0D, 3.0F, 7.0F));
  72.  
  73.  
  74.  
  75. }
  76.  
  77.  
  78.  
  79. @Override
  80. public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor)
  81. {
  82.  
  83.  
  84. EntityTippedArrow entitytippedarrow = new EntityTippedArrow(this.world, this);
  85. double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
  86. double d1 = target.posX - this.posX;
  87. double d2 = d0 - entitytippedarrow.posY;
  88. double d3 = target.posZ - this.posZ;
  89. float f = MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F;
  90. entitytippedarrow.shoot(d1, d2 + (double)f, d3, 1.6F, 12.0F);
  91. this.playSound(SoundEvents.ENTITY_SNOWMAN_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
  92. this.world.spawnEntity(entitytippedarrow);
  93. PotionEffect potion = new PotionEffect(Potion.getPotionById(2), 100, 2);
  94.  
  95. if(target.hitByEntity(entitytippedarrow)==true)
  96. {
  97. target.addPotionEffect(potion);
  98. }
  99.  
  100.  
  101.  
  102. EntityTippedArrow entitytippedarrow2 = new EntityTippedArrow(this.world, this);
  103. double d4 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
  104. double d5 = target.posX - this.posX;
  105. double d6 = d4 - entitytippedarrow2.posY;
  106. double d7 = target.posZ - this.posZ;
  107. float f2 = MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F;
  108. entitytippedarrow2.shoot(d1, d2 + (double)f, d3, 1.6F, 12.0F);
  109. this.playSound(SoundEvents.ENTITY_SNOWMAN_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
  110. this.world.spawnEntity(entitytippedarrow2);
  111. PotionEffect potion2 = new PotionEffect(Potion.getPotionById(2), 100, 2);
  112.  
  113. if(target.hitByEntity(entitytippedarrow2)==true)
  114. {
  115. target.addPotionEffect(potion2);
  116. }
  117.  
  118.  
  119.  
  120. EntityTippedArrow entitytippedarrow3 = new EntityTippedArrow(this.world, this);
  121. double d8 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
  122. double d9 = target.posX - this.posX;
  123. double d10 = d4 - entitytippedarrow3.posY;
  124. double d11 = target.posZ - this.posZ;
  125. float f3 = MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F;
  126. entitytippedarrow3.shoot(d1, d2 + (double)f, d3, 1.6F, 12.0F);
  127. this.playSound(SoundEvents.ENTITY_SNOWMAN_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
  128. this.world.spawnEntity(entitytippedarrow3);
  129. PotionEffect potion3 = new PotionEffect(Potion.getPotionById(2), 100, 2);
  130.  
  131. if(target.hitByEntity(entitytippedarrow3)==true)
  132. {
  133. target.addPotionEffect(potion3);
  134. }
  135. }
  136.  
  137. @Override
  138. public void setSwingingArms(boolean swingingArms) {
  139. // TODO Auto-generated method stub
  140.  
  141. }
  142.  
  143. protected void mountTo(EntityPlayer player)
  144. {
  145. player.rotationYaw = this.rotationYaw;
  146. player.rotationPitch = this.rotationPitch;
  147.  
  148.  
  149. if (!this.world.isRemote)
  150. {
  151. player.startRiding(this);
  152. }
  153. }
  154.  
  155. private static final Set<Item> TAME_ITEMS = Sets.newHashSet(ModItems.SAPPHIRE);
  156. private static final Item DEADLY_ITEM = ModItems.ANTI_PET_CHARM;
  157.  
  158.  
  159.  
  160.  
  161. @Override
  162. public boolean processInteract(EntityPlayer player, EnumHand hand) {
  163. {
  164. ItemStack itemstack = player.getHeldItem(hand);
  165.  
  166. if (!this.isTamed() && TAME_ITEMS.contains(itemstack.getItem()))
  167. {
  168. if (!player.capabilities.isCreativeMode)
  169. {
  170. itemstack.shrink(1);
  171. }
  172.  
  173. if (!this.isSilent())
  174. {
  175. this.world.playSound((EntityPlayer)null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PARROT_EAT, this.getSoundCategory(), 1.0F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
  176. }
  177.  
  178. if (!this.world.isRemote)
  179. {
  180. if (this.rand.nextInt(10) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, player))
  181. {
  182. this.setTamedBy(player);
  183. this.playTameEffect(true);
  184. this.world.setEntityState(this, (byte)7);
  185. }
  186. else
  187. {
  188. this.playTameEffect(false);
  189. this.world.setEntityState(this, (byte)6);
  190. }
  191. }
  192.  
  193. return true;
  194. }
  195. else if (itemstack.getItem() == DEADLY_ITEM)
  196. {
  197. if (!player.capabilities.isCreativeMode)
  198. {
  199. itemstack.shrink(1);
  200. }
  201.  
  202. this.addPotionEffect(new PotionEffect(MobEffects.POISON, 900));
  203.  
  204. if (player.isCreative() || !this.getIsInvulnerable())
  205. {
  206. this.attackEntityFrom(DamageSource.causePlayerDamage(player), Float.MAX_VALUE);
  207. }
  208.  
  209. return true;
  210. }
  211. else
  212. {
  213. return super.processInteract(player, hand);
  214.  
  215.  
  216. }
  217. }
  218. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement