package ru.dbotthepony.mc.otm.block.decorative

import net.minecraft.ChatFormatting
import net.minecraft.core.BlockPos
import net.minecraft.network.chat.Component
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.monster.Zombie
import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.TooltipFlag
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.block.TrapDoorBlock
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.properties.BlockSetType
import ru.dbotthepony.mc.otm.core.TranslatableComponent

class TritaniumTrapdoorBlock(val color: DyeColor?) : TrapDoorBlock(
	Properties.of()
		.mapColor(color ?: DyeColor.LIGHT_BLUE)
		.explosionResistance(80f)
		.noOcclusion().destroyTime(3f)
		.requiresCorrectToolForDrops()
		.isValidSpawn { _: BlockState, _: BlockGetter, _: BlockPos, _: EntityType<*>? -> false },
	BlockSetType.IRON
) {
	override fun appendHoverText(
		p_49816_: ItemStack,
		p_49817_: BlockGetter?,
		p_49818_: MutableList<Component>,
		p_49819_: TooltipFlag
	) {
		super.appendHoverText(p_49816_, p_49817_, p_49818_, p_49819_)
		p_49818_.add(TranslatableComponent("$descriptionId.description0").withStyle(ChatFormatting.DARK_GRAY))
		p_49818_.add(TranslatableComponent("$descriptionId.description1").withStyle(ChatFormatting.DARK_GRAY))

		if (color != null) {
			p_49818_.add(TranslatableComponent("$descriptionId.description2").withStyle(ChatFormatting.DARK_GRAY))
		}
	}

	override fun canEntityDestroy(
		state: BlockState,
		level: BlockGetter,
		pos: BlockPos,
		entity: Entity
	): Boolean {
		return entity !is Zombie && super.canEntityDestroy(state, level, pos, entity)
	}
}
