Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MiniCrossbowItem extends ShootableItem implements IVanishable {
- public final int cooldownSpeed;
- private final int damage;
- public MiniCrossbowItem(IItemTier tierIn, int cooldownSpeedIn, int damageIn, Item.Properties propertiesIn) {
- super(propertiesIn);
- this.cooldownSpeed = cooldownSpeedIn;
- this.damage = damageIn;
- }
- @Override
- public int getItemStackLimit(ItemStack stack) {
- return 1;
- }
- @Override
- public Predicate<ItemStack> getInventoryAmmoPredicate() {
- return ARROWS;
- }
- @Override
- public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
- ItemStack itemstack = playerIn.getHeldItem(handIn);
- Vector3d aim = playerIn.getLookVec();
- ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW);
- AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerIn);
- abstractarrowentity.setDamage(abstractarrowentity.getDamage() + damage);
- ItemStack arrow = playerIn.findAmmo(itemstack);
- CompoundNBT nbt = itemstack.getTag();
- boolean flag1 = playerIn.abilities.isCreativeMode || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, arrow, playerIn));
- boolean flag = !playerIn.findAmmo(itemstack).isEmpty();
- if (!worldIn.isRemote) {
- ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
- if (ret != null) return ret;
- if (!playerIn.abilities.isCreativeMode && !flag) {
- worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.BLOCK_DISPENSER_FAIL, SoundCategory.NEUTRAL, 1.0F, 1.5F);
- } else {
- playerIn.setActiveHand(handIn);
- abstractarrowentity.shoot(aim.x, aim.y, aim.z, 3.0f, 1.0f);
- worldIn.addEntity(abstractarrowentity);
- worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ITEM_CROSSBOW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.5F);
- if(nbt == null) { nbt = new CompoundNBT(); }
- if(nbt.contains("shots")) { nbt.putInt("shots", nbt.getInt("shots") + 1); }
- else { nbt.putInt("shots", 1); }
- System.out.println(nbt.getInt("shots"));
- itemstack.setTag(nbt);
- }
- if (!playerIn.abilities.isCreativeMode) {
- arrow.shrink(1);
- if (arrow.isEmpty()) {
- playerIn.inventory.deleteStack(arrow);
- }
- }
- playerIn.getCooldownTracker().setCooldown(this, cooldownSpeed);
- if (flag1 || playerIn.abilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
- abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
- }
- }
- if (!playerIn.abilities.isCreativeMode && !flag) {
- return ActionResult.resultFail(itemstack);
- } else {
- playerIn.setActiveHand(handIn);
- if (!playerIn.abilities.isCreativeMode) {
- itemstack.damageItem(1, playerIn, (p_220045_0_) -> {
- p_220045_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
- });
- }
- return ActionResult.resultConsume(itemstack);
- }
- }
- @OnlyIn(Dist.CLIENT)
- public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
- super.addInformation(stack, worldIn, tooltip, flagIn);
- tooltip.add((new TranslationTextComponent("shots " + stack.getChildTag("shots"))).func_240699_a_(TextFormatting.GRAY));
- }
- @Override
- public int func_230305_d_() {
- return 8;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement