Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.theishiopian.BeamCannon;
- import java.util.ArrayList;
- import java.util.List;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.EnumAction;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.ActionResult;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.EnumActionResult;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class ItemBeamCannon extends Item
- {
- public ItemBeamCannon()
- {
- this.setUnlocalizedName("beam_cannon");
- this.setRegistryName("beam_cannon");
- this.setCreativeTab(CreativeTabs.COMBAT);
- this.setMaxStackSize(1);
- }
- @Override
- public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
- {
- System.out.println("0");
- double posX = playerIn.posX + playerIn.getLookVec().xCoord
- + (playerIn.width / 2.0) * Math.sin(Math.toRadians(-playerIn.rotationYaw - 90));
- double posY = playerIn.posY + playerIn.getEyeHeight() - 0.2 + playerIn.getLookVec().yCoord;
- double posZ = playerIn.posZ + playerIn.getLookVec().zCoord
- + (playerIn.width / 2.0) * Math.cos(Math.toRadians(-playerIn.rotationYaw - 90));
- double targX = playerIn.posX + playerIn.getLookVec().xCoord * 96.0f
- + (30.0 * 1 * (itemRand.nextFloat() - 0.5));
- double targY = playerIn.posY + playerIn.getLookVec().yCoord * 96.0f
- + (30.0 * 1 * (itemRand.nextFloat() - 0.5));
- double targZ = playerIn.posZ + playerIn.getLookVec().zCoord * 96.0f
- + (30.0 * 1 * (itemRand.nextFloat() - 0.5));
- double dX = targX - posX;
- double dY = targY - posY;
- double dZ = targZ - posZ;
- boolean doContinue = true;
- if(!worldIn.isRemote)
- {
- PacketHandler.INSTANCE
- .sendToAll(new EnergyBeam(playerIn.getUniqueID(), posX, posY, posZ, dX, dY, dZ));
- }
- for (double i = 0; i < 384.0 && doContinue; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- posX += 0.2 * i * dX / 384.0;
- posY += 0.2 * i * dY / 384.0;
- posZ += 0.2 * i * dZ / 384.0;
- }
- IBlockState state = worldIn.getBlockState(new BlockPos(posX, posY, posZ));
- if(state.isFullCube() && state.isOpaqueCube())
- {
- doContinue = false;
- }
- List<EntityLivingBase> rawEntities = worldIn.getEntitiesWithinAABB(EntityLivingBase.class,
- new AxisAlignedBB(posX - 0.85, posY - 0.85, posZ - 0.85, posX + 0.85, posY + 0.85, posZ + 0.85));
- ArrayList<EntityLivingBase> entities = new ArrayList<EntityLivingBase>();
- for (int j = 0; j < rawEntities.size(); j++)
- {
- if(rawEntities.get(j).getUniqueID().compareTo(playerIn.getUniqueID()) != 0)
- {
- entities.add(rawEntities.get(j));
- }
- }
- if(entities.size() > 0)
- {
- entities.get(0).setFire(1);
- entities.get(0).attackEntityFrom(DamageSource.causeMobDamage(playerIn), 7.0f);
- entities.get(0).setLastAttacker(playerIn);
- entities.get(0).setRevengeTarget(playerIn);
- entities.get(0).knockBack(playerIn, 0.5f, -dX, -dZ);
- doContinue = false;
- }
- }
- return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
- }
- @Override
- public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
- {
- return slotChanged || newStack.getItem() != oldStack.getItem();
- }
- @Override
- public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected)
- {
- if(!stack.hasTagCompound())
- {
- stack.setTagCompound(new NBTTagCompound());
- stack.getTagCompound().setInteger("cooldown", 0);
- }
- else
- {
- if(stack.getTagCompound().getInteger("cooldown") > 0)
- {
- stack.getTagCompound().setInteger("cooldown", stack.getTagCompound().getInteger("cooldown") - 1);
- }
- }
- }
- @Override
- public int getMaxItemUseDuration(ItemStack stack)
- {
- return 72000;
- }
- @Override
- public EnumAction getItemUseAction(ItemStack stack)
- {
- return EnumAction.BOW;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement