package com.leisuretimedock.blasttravelreborn.content.item;

import com.leisuretimedock.blasttravelreborn.content.entity.BTREntityTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.UseOnContext;
import org.jetbrains.annotations.NotNull;

public class CannonItem extends Item {
	public CannonItem(Properties settings) {
		super(settings);
	}

	@Override
	public @NotNull InteractionResult useOn(UseOnContext context) {
		if (context.getLevel() instanceof ServerLevel world) {
			BTREntityTypes.CANNON_ENTITY.get().spawn(world, context.getItemInHand(), context.getPlayer(), context.getClickedPos().relative(context.getClickedFace()), MobSpawnType.SPAWN_EGG, true, false);
			if (context.getPlayer() != null && !context.getPlayer().isCreative()) {
				context.getItemInHand().shrink(1);
			}
		}
		context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundSource.BLOCKS, 1, 0.8f);

		return InteractionResult.sidedSuccess(context.getLevel().isClientSide());
	}
}
