ExtraHoppers/src/main/kotlin/net/shadowfacts/extrahoppers/block/gold/GoldHopperBlock.kt

47 lines
1.6 KiB
Kotlin

package net.shadowfacts.extrahoppers.block.gold
import net.fabricmc.fabric.api.block.FabricBlockSettings
import net.fabricmc.fabric.api.container.ContainerProviderRegistry
import net.minecraft.block.BlockState
import net.minecraft.block.Material
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.sound.BlockSoundGroup
import net.minecraft.stat.Stats
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.Identifier
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.math.BlockPos
import net.minecraft.world.BlockView
import net.minecraft.world.World
import net.shadowfacts.extrahoppers.block.base.BaseHopperBlock
/**
* @author shadowfacts
*/
class GoldHopperBlock: BaseHopperBlock<GoldHopperBlockEntity>(
FabricBlockSettings.of(Material.METAL)
.strength(3f, 6f)
.sounds(BlockSoundGroup.METAL)
.nonOpaque()
.build()
) {
companion object {
val ID = Identifier("extrahoppers", "gold_hopper")
}
override fun createBlockEntity(world: BlockView) = GoldHopperBlockEntity()
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult): ActionResult {
if (!world.isClient) {
player.incrementStat(Stats.INSPECT_HOPPER)
ContainerProviderRegistry.INSTANCE.openContainer(GoldHopperContainer.ID, player) { buf ->
buf.writeBlockPos(pos)
}
}
return ActionResult.SUCCESS
}
}