Feroov Posted January 1, 2022 Posted January 1, 2022 Here is my main class for it: public class Musket extends BowItem { public Musket(Properties p_40660_) { super(p_40660_); } @Override public int getDefaultProjectileRange() { return 15; } @Override public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) { if (entityLiving instanceof Player) { Player playerentity = (Player) entityLiving; if (stack.getDamageValue() < (stack.getMaxDamage() - 1)) { playerentity.getCooldowns().addCooldown(this, 45); Player player = (Player) entityLiving; ItemStack itemstack = player.getProjectile(stack); if (itemstack.isEmpty()) { itemstack = new ItemStack(ModItems.MUSKET_BULLET.get()); } MusketBullet arrowitem = (MusketBullet) (itemstack.getItem() instanceof MusketBullet ? itemstack.getItem() : ModItems.MUSKET_BULLET.get()); MusketAmmo abstractarrow = (MusketAmmo) arrowitem.createMusket(worldIn, itemstack, player); abstractarrow = customeArrow(abstractarrow); boolean flag1 = player.getAbilities().instabuild || (itemstack.getItem() instanceof MusketBullet && ((MusketBullet) itemstack.getItem()) .isInfinite(itemstack, stack, player)); if (!worldIn.isClientSide) { MusketAmmo abstractarrowentity = createArrow(worldIn, stack, playerentity); abstractarrowentity = customeArrow(abstractarrowentity); abstractarrowentity.shootFromRotation(playerentity, playerentity.getXRot(), playerentity.getYRot(), 0.0F, 1.0F * 3.0F, 1.0F); abstractarrowentity.setBaseDamage(2.5); abstractarrowentity.tickCount = 35; abstractarrowentity.isNoGravity(); stack.hurtAndBreak(1, entityLiving, p -> p.broadcastBreakEvent(entityLiving.getUsedItemHand())); worldIn.addFreshEntity(abstractarrowentity); worldIn.playSound((Player) null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), ModSoundEvents.MUSKET.get(), SoundSource.PLAYERS, 1.0F, 1.0F / (worldIn.random.nextFloat() * 0.4F + 1.2F) + 0.25F * 0.5F); if (!flag1 && !player.getAbilities().instabuild) { itemstack.shrink(1); if (itemstack.isEmpty()) { player.getInventory().removeItem(itemstack); } } } } } } public InteractionResultHolder<ItemStack> use(Level p_40672_, Player p_40673_, InteractionHand p_40674_) { ItemStack itemstack = p_40673_.getItemInHand(p_40674_); boolean flag = !p_40673_.getProjectile(itemstack).isEmpty(); InteractionResultHolder<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, p_40672_, p_40673_, p_40674_, flag); if (ret != null) return ret; if (!p_40673_.getAbilities().instabuild && !flag) { return InteractionResultHolder.fail(itemstack); } else { p_40673_.startUsingItem(p_40674_); return InteractionResultHolder.consume(itemstack); } } public MusketAmmo createArrow(Level worldIn, ItemStack stack, LivingEntity shooter) { MusketAmmo arrowentity = new MusketAmmo(worldIn, shooter); return arrowentity; } @Override public UseAnim getUseAnimation(ItemStack stack) { return UseAnim.BOW; } public MusketAmmo customeArrow(MusketAmmo arrow) { return arrow; } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.