Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.20 KB | None | 0 0
  1. package com.theishiopian.BeamCannon;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import net.minecraft.block.state.IBlockState;
  7. import net.minecraft.creativetab.CreativeTabs;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.EntityLivingBase;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.EnumAction;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.util.ActionResult;
  16. import net.minecraft.util.DamageSource;
  17. import net.minecraft.util.EnumActionResult;
  18. import net.minecraft.util.EnumHand;
  19. import net.minecraft.util.math.AxisAlignedBB;
  20. import net.minecraft.util.math.BlockPos;
  21. import net.minecraft.world.World;
  22.  
  23. public class ItemBeamCannon extends Item
  24. {
  25.     public ItemBeamCannon()
  26.     {
  27.         this.setUnlocalizedName("beam_cannon");
  28.         this.setRegistryName("beam_cannon");
  29.         this.setCreativeTab(CreativeTabs.COMBAT);
  30.         this.setMaxStackSize(1);
  31.     }
  32.  
  33.     @Override
  34.     public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  35.     {
  36.         System.out.println("0");
  37.         double posX = playerIn.posX + playerIn.getLookVec().xCoord
  38.                 + (playerIn.width / 2.0) * Math.sin(Math.toRadians(-playerIn.rotationYaw - 90));
  39.         double posY = playerIn.posY + playerIn.getEyeHeight() - 0.2 + playerIn.getLookVec().yCoord;
  40.         double posZ = playerIn.posZ + playerIn.getLookVec().zCoord
  41.                 + (playerIn.width / 2.0) * Math.cos(Math.toRadians(-playerIn.rotationYaw - 90));
  42.  
  43.         double targX = playerIn.posX + playerIn.getLookVec().xCoord * 96.0f
  44.                 + (30.0 * 1 * (itemRand.nextFloat() - 0.5));
  45.         double targY = playerIn.posY + playerIn.getLookVec().yCoord * 96.0f
  46.                 + (30.0 * 1 * (itemRand.nextFloat() - 0.5));
  47.         double targZ = playerIn.posZ + playerIn.getLookVec().zCoord * 96.0f
  48.                 + (30.0 * 1 * (itemRand.nextFloat() - 0.5));
  49.  
  50.         double dX = targX - posX;
  51.         double dY = targY - posY;
  52.         double dZ = targZ - posZ;
  53.         boolean doContinue = true;
  54.         if(!worldIn.isRemote)
  55.         {
  56.             PacketHandler.INSTANCE
  57.                     .sendToAll(new EnergyBeam(playerIn.getUniqueID(), posX, posY, posZ, dX, dY, dZ));
  58.         }
  59.         for (double i = 0; i < 384.0 && doContinue; i++)
  60.         {
  61.             for (int j = 0; j < 5; j++)
  62.             {
  63.                 posX += 0.2 * i * dX / 384.0;
  64.                 posY += 0.2 * i * dY / 384.0;
  65.                 posZ += 0.2 * i * dZ / 384.0;
  66.             }
  67.             IBlockState state = worldIn.getBlockState(new BlockPos(posX, posY, posZ));
  68.             if(state.isFullCube() && state.isOpaqueCube())
  69.             {
  70.                 doContinue = false;
  71.             }
  72.             List<EntityLivingBase> rawEntities = worldIn.getEntitiesWithinAABB(EntityLivingBase.class,
  73.                     new AxisAlignedBB(posX - 0.85, posY - 0.85, posZ - 0.85, posX + 0.85, posY + 0.85, posZ + 0.85));
  74.             ArrayList<EntityLivingBase> entities = new ArrayList<EntityLivingBase>();
  75.             for (int j = 0; j < rawEntities.size(); j++)
  76.             {
  77.                 if(rawEntities.get(j).getUniqueID().compareTo(playerIn.getUniqueID()) != 0)
  78.                 {
  79.                     entities.add(rawEntities.get(j));
  80.                 }
  81.             }
  82.             if(entities.size() > 0)
  83.             {
  84.                 entities.get(0).setFire(1);
  85.                 entities.get(0).attackEntityFrom(DamageSource.causeMobDamage(playerIn), 7.0f);
  86.                 entities.get(0).setLastAttacker(playerIn);
  87.                 entities.get(0).setRevengeTarget(playerIn);
  88.                 entities.get(0).knockBack(playerIn, 0.5f, -dX, -dZ);
  89.                 doContinue = false;
  90.             }
  91.         }
  92.         return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
  93.     }
  94.  
  95.     @Override
  96.     public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
  97.     {
  98.         return slotChanged || newStack.getItem() != oldStack.getItem();
  99.     }
  100.  
  101.     @Override
  102.     public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected)
  103.     {
  104.         if(!stack.hasTagCompound())
  105.         {
  106.             stack.setTagCompound(new NBTTagCompound());
  107.             stack.getTagCompound().setInteger("cooldown", 0);
  108.         }
  109.         else
  110.         {
  111.             if(stack.getTagCompound().getInteger("cooldown") > 0)
  112.             {
  113.                 stack.getTagCompound().setInteger("cooldown", stack.getTagCompound().getInteger("cooldown") - 1);
  114.             }
  115.         }
  116.     }
  117.  
  118.     @Override
  119.     public int getMaxItemUseDuration(ItemStack stack)
  120.     {
  121.         return 72000;
  122.     }
  123.  
  124.     @Override
  125.     public EnumAction getItemUseAction(ItemStack stack)
  126.     {
  127.         return EnumAction.BOW;
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement