Facebook
From Harmless Marmoset, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 150
  1. public class ChargeableStaffItem extends TieredItem
  2. {
  3.     private final int cooldownSpeed;
  4.     private final int fireType;
  5.     private final int xpAmount;
  6.  
  7.     public ChargeableStaffItem(IItemTier tierIn, int cooldownSpeedIn, int firetypeIn, int xpAmountIn, Properties properties) {
  8.         super(tierIn, properties);
  9.  
  10.         this.cooldownSpeed = cooldownSpeedIn;
  11.         this.fireType = firetypeIn;
  12.         this.xpAmount = xpAmountIn;
  13.     }
  14.  
  15.  
  16.  
  17.     @Override
  18.     public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
  19.         if (entityLiving instanceof PlayerEntity) {
  20.             PlayerEntity playerIn = (PlayerEntity) entityLiving;
  21.             Hand handIn = (Hand) playerIn.getActiveHand();
  22.  
  23.             Vector3d aim = playerIn.getLookVec();
  24.  
  25.             double x = playerIn.getPosX();
  26.             double y = playerIn.getPosY();
  27.             double z = playerIn.getPosZ();
  28.  
  29.             if (fireType == 1) {
  30.                 if (timeLeft <= 7170) {
  31.                     if (playerIn.experienceTotal > 0 || playerIn.abilities.isCreativeMode) {
  32.                         if (!worldIn.isRemote) {
  33.                             IceBallEntity iceball = new IceBallEntity(playerIn, worldIn);
  34.                             IceBallEntity iceball2 = new IceBallEntity(playerIn, worldIn);
  35.                             IceBallEntity iceball3 = new IceBallEntity(playerIn, worldIn);
  36.                             iceball.shoot(aim.x, aim.y, aim.z, 1.5f, 1.0f);
  37.                             iceball2.shoot(aim.x, aim.y, aim.z * 0.5, 1.5f, 1.0f);              //<--- I'm trying to get iceball2 and 3 to be on the opposites sides of iceball but they're acting funky
  38.                             iceball3.shoot(aim.x, aim.y, aim.z * -0.5, 1.5f, 1.0f);
  39.                             worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_EVOKER_CAST_SPELL, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  40.                             worldIn.addEntity(iceball);
  41.                             worldIn.addEntity(iceball2);
  42.                             worldIn.addEntity(iceball3);
  43.                         }
  44.  
  45.                     }
  46.                 }
  47.                     else {
  48.                         if (playerIn.experienceTotal > 0 || playerIn.abilities.isCreativeMode) {
  49.                             if (!worldIn.isRemote) {
  50.                                 IceBallEntity iceball = new IceBallEntity(playerIn, worldIn);
  51.                                 iceball.shoot(aim.x, aim.y, aim.z, 1.5f, 1.0f);
  52.                                 worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_EVOKER_CAST_SPELL, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  53.                                 worldIn.addEntity(iceball);
  54.                             }
  55.                         }
  56.                     }
  57.             }
  58.  
  59.                 if (!playerIn.abilities.isCreativeMode) {
  60.                     stack.damageItem(1, playerIn, (p_220045_0_) -> {
  61.                         p_220045_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
  62.                     });
  63.                     playerIn.giveExperiencePoints(this.xpAmount * -1);
  64.                 }
  65.  
  66.             playerIn.swingArm(handIn);
  67.             playerIn.getCooldownTracker().setCooldown(this, cooldownSpeed);
  68.             playerIn.addStat(Stats.ITEM_USED.get(this));
  69.  
  70.         }
  71.  
  72.     }
  73.  
  74.     public int getUseDuration(ItemStack stack) {
  75.         return 7200;
  76.     }
  77.  
  78.     public UseAction getUseAction(ItemStack stack) {
  79.         return UseAction.BOW;
  80.     }
  81.  
  82.     public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
  83.         ItemStack itemstack = playerIn.getHeldItem(handIn);
  84.  
  85.  
  86.  
  87.         if (!playerIn.abilities.isCreativeMode && playerIn.experienceTotal == 0) {
  88.             worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_EVOKER_CAST_SPELL, SoundCategory.NEUTRAL, 1.0F, -1.0F);
  89.             playerIn.swingArm(handIn);
  90.             playerIn.getCooldownTracker().setCooldown(this, cooldownSpeed);
  91.             return ActionResult.resultFail(itemstack);
  92.         } else {
  93.             playerIn.setActiveHand(handIn);
  94.             return ActionResult.resultConsume(itemstack);
  95.         }
  96.     }
  97.  
  98.  
  99.     @Override
  100.     public void onUsingTick(ItemStack stack, LivingEntity player, int count) {
  101.  
  102.         //player.world.playSound((PlayerEntity) null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  103.  
  104.  
  105.     }
  106.  
  107.     @OnlyIn(Dist.CLIENT)
  108.     public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
  109.         super.addInformation(stack, worldIn, tooltip, flagIn);
  110.         tooltip.add((new TranslationTextComponent("Chargeable")).func_240699_a_(TextFormatting.WHITE));
  111.         tooltip.add((new TranslationTextComponent("Cooldown: " + this.cooldownSpeed)).func_240699_a_(TextFormatting.WHITE));
  112.         tooltip.add((new TranslationTextComponent("Xp Cost: " + this.xpAmount)).func_240699_a_(TextFormatting.WHITE));
  113.     }
  114. }