package top.r3944realms.lib39.example.content.item;

import net.minecraft.client.Minecraft;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.example.client.screen.ForgeScreen;

/**
 * The type Forge item.
 */
public class ForgeItem extends Item {
    /**
     * Instantiates a new Forge item.
     *
     * @param properties the properties
     */
    public ForgeItem(Properties properties) {
        super(properties);
    }

    @Override
    public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand usedHand) {
        if (level.isClientSide() && usedHand == InteractionHand.MAIN_HAND) {
            clientUse(usedHand);
        }
        return super.use(level, player, usedHand);
    }

    @OnlyIn(Dist.CLIENT)
    private static void clientUse(@NotNull InteractionHand usedHand) {
        Minecraft.getInstance().setScreen(new ForgeScreen(usedHand, 0));
    }
}