Fabric Mod

GunpowderMod

crea una mod per 1.21.4 fabric, la mod deve aggiunger armi da fuoco ed essere compatibile con CursedForge

src/main/java/eu/codexe/gunpowdermod/item/PistolItem.java
package eu.codexe.gunpowdermod.item;

import eu.codexe.gunpowdermod.content.ModItems;
import eu.codexe.gunpowdermod.entity.ModEntities;
import eu.codexe.gunpowdermod.entity.projectile.BulletEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.consume.UseAction;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;

public class PistolItem extends Item {
    public PistolItem(Settings settings) {
        super(settings);
    }

    @Override
    public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
        ItemStack stack = user.getStackInHand(hand);
        if (!user.getInventory().contains(ModItems.BULLET.getDefaultStack()) && !user.getAbilities().creativeMode) {
            return TypedActionResult.fail(stack);
        }
        user.setCurrentHand(hand);
        return TypedActionResult.consume(stack);
    }

    @Override
    public UseAction getUseAction(ItemStack stack) {
        return UseAction.BOW;
    }

    @Override
    public int getMaxUseTime(ItemStack stack, LivingEntity user) {
        return 20;
    }

    @Override
    public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
        if (!(user instanceof PlayerEntity player)) {
            return;
        }
        int usedTicks = this.getMaxUseTime(stack, user) - remainingUseTicks;
        if (usedTicks < 5) {
            return;
        }
        if (!world.isClient) {
            ItemStack bulletStack = findBullet(player);
            if (bulletStack.isEmpty() && !player.getAbilities().creativeMode) {
                return;
            }
            if (!player.getAbilities().creativeMode) {
                bulletStack.decrement(1);
            }
            BulletEntity bullet = new BulletEntity(ModEntities.BULLET, world, player);