Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.84 KB | None | 0 0
  1. package com.theishiopian.foragecraft.entity;
  2.  
  3. import com.theishiopian.foragecraft.init.ModBlocks;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.entity.item.EntityItem;
  9. import net.minecraft.entity.projectile.EntityThrowable;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.util.DamageSource;
  14. import net.minecraft.util.EnumParticleTypes;
  15. import net.minecraft.util.math.RayTraceResult;
  16. import net.minecraft.util.math.RayTraceResult.Type;
  17. import net.minecraft.world.World;
  18. import net.minecraftforge.fml.relauncher.Side;
  19. import net.minecraftforge.fml.relauncher.SideOnly;
  20.  
  21.  
  22.  
  23. public class EntityRockFlat extends EntityThrowable
  24. {
  25.     public float pitch, yaw;
  26.     public int skips = 0;
  27.    
  28.     public EntityRockFlat(World worldIn)
  29.     {
  30.         super(worldIn);
  31.     }
  32.  
  33.     public EntityRockFlat(World worldIn, EntityLivingBase throwerIn)
  34.     {
  35.         super(worldIn, throwerIn);
  36.         this.pitch = this.rotationPitch;
  37.         this.yaw = this.rotationYaw;
  38.     }
  39.  
  40.     public EntityRockFlat(World worldIn, double x, double y, double z)
  41.     {
  42.         super(worldIn, x, y, z);
  43.     }
  44.    
  45.     public EntityRockFlat(World worldIn, double x, double y, double z, int skips)
  46.     {
  47.         super(worldIn, x, y, z);
  48.         this.skips = skips;
  49.        
  50.         this.setHeadingFromThrower(this, this.pitch, this.yaw, 0.0F, 1.5F, 0.0F);
  51.     }
  52.    
  53.  
  54.     @SideOnly(Side.CLIENT)
  55.     public void handleStatusUpdate(byte id)
  56.     {
  57.         if(id == 3)
  58.         {
  59.             for (int i = 0; i < 8; ++i)
  60.             {
  61.                 this.world.spawnParticle(EnumParticleTypes.BLOCK_DUST, this.posX, this.posY, this.posZ, 0.0D, 0.0D,
  62.                         0.0D, new int[] { Block.getIdFromBlock(Blocks.STONE) });
  63.             }
  64.         }
  65.     }
  66.  
  67.     /**
  68.      * Called when this EntityThrowable hits a block or entity.
  69.      */
  70.     protected void onImpact(RayTraceResult result)
  71.     {
  72.         if(!this.world.isRemote)
  73.         {
  74.             if(result.typeOfHit == Type.BLOCK)
  75.             {
  76.                
  77.                 if(skips < 3)
  78.                 {
  79.                     System.out.println("Pitch: "+this.rotationPitch+" Yaw: "+this.rotationYaw);
  80.                     this.setDead();
  81.                     EntityThrowable rock = new EntityRockFlat(world, this.posX, this.posY, this.posZ, skips+1);
  82.                     world.spawnEntity(rock);
  83.                    
  84.                 }
  85.                 else
  86.                 {
  87.                     ItemStack refund = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_flat));
  88.                    
  89.                     world.spawnEntity(new EntityItem(world, this.posX, this.posY, this.posZ, refund));
  90.    
  91.                     setDead();
  92.                 }
  93.                    
  94.                
  95.                
  96.                
  97.                
  98. //              if(world.getBlockState(result.getBlockPos()).getCollisionBoundingBox(world,
  99. //                      result.getBlockPos()) != null)
  100. //              {
  101. //                  Material impactMaterial = world.getBlockState(result.getBlockPos()).getBlock()
  102. //                          .getMaterial(world.getBlockState(result.getBlockPos()));
  103. //                  Block impactBlock = world.getBlockState(result.getBlockPos()).getBlock();
  104. //
  105. //                  if(impactMaterial == Material.GLASS)
  106. //                  {
  107. //                      this.world.setBlockToAir(result.getBlockPos());
  108. //                      this.world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_GLASS_BREAK,
  109. //                              SoundCategory.HOSTILE, 1, 1);
  110. //                  }
  111. //                  else
  112. //                  {
  113. //                      this.world.playSound(null, posX, posY, posZ, impactBlock.getSoundType().getBreakSound(),
  114. //                              SoundCategory.HOSTILE, 1, 1);
  115. //
  116. //                      ItemStack refund = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_flat));
  117. //                         
  118. //                      world.spawnEntity(new EntityItem(world, this.posX, this.posY, this.posZ, refund));
  119. //
  120. //                      setDead();
  121. //                  }
  122. //              }
  123.             }
  124.             else if(result.entityHit != null)
  125.             {
  126.                 int damage = 2;
  127.                 ItemStack refund = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_flat));
  128.                
  129.                 result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float) damage);
  130.                
  131.                 setDead();
  132.                 world.spawnEntity(new EntityItem(world, this.posX, this.posY, this.posZ, refund));
  133.             }
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement