Guest User

Bullet

a guest
Jan 30th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. //Copyright (C) 2016 Andrew Morin
  2. //Licensed under GNU GPL v3; see license.txt for complete license terms + conditions etc.
  3.  
  4. package theishiopian.gunmod.entity;
  5.  
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.projectile.EntityThrowable;
  8. import net.minecraft.init.Blocks;
  9. import net.minecraft.init.SoundEvents;
  10. import net.minecraft.util.DamageSource;
  11. import net.minecraft.util.EnumParticleTypes;
  12. import net.minecraft.util.SoundCategory;
  13. import net.minecraft.util.math.BlockPos;
  14. import net.minecraft.util.math.RayTraceResult;
  15. import net.minecraft.util.math.RayTraceResult.Type;
  16. import net.minecraft.world.World;
  17.  
  18. import java.util.Random;
  19.  
  20. public class EntityBullet extends EntityThrowable
  21. {
  22.     public EntityBullet(World world)
  23.     {
  24.         super(world);
  25.     }
  26.    
  27.    
  28.     public EntityBullet(World world, EntityLivingBase entity)
  29.     {
  30.         super(world, entity);
  31.         this.ignoreEntity = entity;
  32.     }
  33.  
  34.     public EntityBullet(World world, double x, double y, double z)
  35.     {
  36.         super(world, x, y, z);
  37.     }
  38.    
  39.     @Override
  40.     protected void onImpact(RayTraceResult result)
  41.     {
  42.         if(result.typeOfHit == Type.BLOCK)
  43.         {
  44.             if(world.getBlockState(result.getBlockPos()).getCollisionBoundingBox(world, result.getBlockPos()) != null)setDead();
  45.         }
  46.         else if(result.entityHit != null)
  47.         {
  48.            
  49.             result.entityHit.attackEntityFrom(DamageSource.GENERIC, 2);
  50.             setDead();
  51.         }
  52.     }
  53.    
  54.     @Override
  55.     public void onUpdate()
  56.     {
  57.         super.onUpdate();
  58.        
  59.         EnumParticleTypes damageIndicator;
  60.        
  61.         if(this.ticksExisted > 10)damageIndicator = EnumParticleTypes.SMOKE_NORMAL;
  62.         else damageIndicator = EnumParticleTypes.FLAME;
  63.        
  64.         if(this.ticksExisted>100)setDead();
  65.        
  66.         this.world.spawnParticle(damageIndicator, true, this.posX, this.posY, this.posZ, this.motionX, this.motionY, this.motionZ, new int[0]);    
  67.     }
  68. }
Add Comment
Please, Sign In to add comment