
package studio.halbear.hem.block;

import studio.halbear.hem.itemgroup.BlueleafTabItemGroup;
import studio.halbear.hem.HemModElements;

import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.common.util.ForgeSoundType;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.common.IPlantable;

import net.minecraft.world.IBlockReader;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Direction;
import net.minecraft.loot.LootContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.item.BlockItem;
import net.minecraft.block.material.Material;
import net.minecraft.block.FallingBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Block;

import java.util.List;
import java.util.Collections;

@HemModElements.ModElement.Tag
public class BlueleafGravelMudBlock extends HemModElements.ModElement {
	@ObjectHolder("hem:blueleaf_gravel_mud")
	public static final Block block = null;

	public BlueleafGravelMudBlock(HemModElements instance) {
		super(instance, 129);
	}

	@Override
	public void initElements() {
		elements.blocks.add(() -> new CustomBlock());
		elements.items
				.add(() -> new BlockItem(block, new Item.Properties().group(BlueleafTabItemGroup.tab)).setRegistryName(block.getRegistryName()));
	}

	public static class CustomBlock extends FallingBlock {
		public CustomBlock() {
			super(Block.Properties.create(Material.EARTH)
					.sound(new ForgeSoundType(1.0f, 1.0f, () -> new SoundEvent(new ResourceLocation("block.soul_soil.break")),
							() -> new SoundEvent(new ResourceLocation("block.gravel.step")),
							() -> new SoundEvent(new ResourceLocation("block.soul_soil.place")),
							() -> new SoundEvent(new ResourceLocation("block.soul_soil.hit")),
							() -> new SoundEvent(new ResourceLocation("block.gravel.fall"))))
					.hardnessAndResistance(0.35f, 3.5f).setLightLevel(s -> 0).harvestLevel(1).harvestTool(ToolType.SHOVEL)
					.slipperiness(0.7999999999999999f));
			setRegistryName("blueleaf_gravel_mud");
		}

		@Override
		public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
			return 15;
		}

		@Override
		public boolean canSustainPlant(BlockState state, IBlockReader world, BlockPos pos, Direction direction, IPlantable plantable) {
			return true;
		}

		@Override
		public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
			List<ItemStack> dropsOriginal = super.getDrops(state, builder);
			if (!dropsOriginal.isEmpty())
				return dropsOriginal;
			return Collections.singletonList(new ItemStack(this, 1));
		}
	}
}
