Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1. package com.tiviacz.chocolatequestrepoured.objects.entity;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityLiving;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.projectile.EntityThrowable;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.util.DamageSource;
  12. import net.minecraft.util.EnumParticleTypes;
  13. import net.minecraft.util.math.AxisAlignedBB;
  14. import net.minecraft.util.math.BlockPos;
  15. import net.minecraft.util.math.RayTraceResult;
  16. import net.minecraft.world.World;
  17. import net.minecraftforge.fml.common.registry.IThrowableEntity;
  18.  
  19. public class EntityProjectileEarthQuake extends EntityThrowable
  20. {
  21.     private int lifeTime = 60;
  22.     private EntityLivingBase thrower;
  23.    
  24.     public EntityProjectileEarthQuake(World worldIn)
  25.     {
  26.         super(worldIn);
  27.     }
  28.    
  29.     public EntityProjectileEarthQuake(World worldIn, double x, double y, double z)
  30.     {
  31.         super(worldIn, x, y, z);
  32.     }
  33.  
  34.     public EntityProjectileEarthQuake(World worldIn, EntityLivingBase throwerIn)
  35.     {
  36.         super(worldIn, throwerIn);
  37.         this.thrower = throwerIn;
  38.        
  39.         float rot = throwerIn.getRotationYawHead();
  40.         this.setRotationYawHead(rot);
  41.        
  42.         this.posY -= 1.25D;
  43.         this.motionX = 0.1D;
  44.         this.motionY = -1.0D;
  45.         this.motionZ = 0.1D;
  46.         this.isImmuneToFire = true;
  47.     }
  48.  
  49.     @Override
  50.     protected void onImpact(RayTraceResult result)
  51.     {
  52.         if(!world.isRemote)
  53.         {
  54.             if(!(result.entityHit instanceof EntityLiving))
  55.             {
  56.                 motionY = 0.0D;
  57.             }
  58.         }
  59.     }
  60.    
  61.     @Override
  62.     public void onUpdate()
  63.     {
  64.         motionX *= 1.01D;
  65.         motionZ *= 1.01D;
  66.        
  67.         if(getThrower() != null && getThrower().isDead)
  68.         {
  69.             setDead();
  70.         }
  71.        
  72.         else
  73.         {
  74.            
  75.             if(ticksExisted++ > 300)
  76.             {
  77.                 setDead();
  78.             }
  79.            
  80.             this.onUpdateInAir();
  81.             super.onUpdate();
  82.         }
  83.     }
  84.    
  85.     private void onUpdateInAir()
  86.     {
  87.         lifeTime -= 1;    
  88.        
  89.         if(lifeTime <= 0)
  90.         {
  91.             setDead();
  92.         }
  93.        
  94.         BlockPos pos = new BlockPos(this.getPosition().getX(), this.getPosition().getY() - 1, this.getPosition().getZ());
  95.         Block block = world.getBlockState(pos).getBlock();
  96.            
  97.         if(block == null || block == Blocks.AIR)
  98.         {
  99.             block = Blocks.GLASS;
  100.         }
  101.            
  102.         double dist = 1.0D;
  103.         AxisAlignedBB var3 = getEntityBoundingBox().expand(dist, 2.0D, dist);
  104.         List<Entity> list = world.getEntitiesWithinAABB(EntityLivingBase.class, var3);
  105.    
  106.         for(Entity entity : list)
  107.         {
  108.             if(entity instanceof EntityLivingBase && entity != getThrower() && !world.isRemote && entity.onGround)
  109.             {
  110.                 entity.motionY = 0.3D;
  111.                 entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this, getThrower()), 1.0F);
  112.             }
  113.         }
  114.        
  115.         if(world.isRemote)
  116.         {
  117.             for(int i = 0; i < 8; i++)
  118.             {
  119.                 world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + rand.nextFloat() - 0.5D, posY + rand.nextFloat() - 0.5D, posZ + rand.nextFloat() - 0.5D, rand.nextFloat() - 0.5F, rand.nextFloat(), rand.nextFloat() - 0.5F, Block.getStateId(world.getBlockState(pos)));
  120.             }
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement