ExtraHoppers/src/main/kotlin/net/shadowfacts/extrahoppers/block/wood/WoodHopperBlock.kt

59 lines
2.1 KiB
Kotlin

package net.shadowfacts.extrahoppers.block.wood
import net.fabricmc.fabric.api.block.FabricBlockSettings
import net.fabricmc.fabric.api.container.ContainerProviderRegistry
import net.minecraft.block.*
import net.minecraft.block.entity.Hopper
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityContext
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemPlacementContext
import net.minecraft.sound.BlockSoundGroup
import net.minecraft.stat.Stats
import net.minecraft.state.StateManager
import net.minecraft.state.property.Properties
import net.minecraft.util.*
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.util.shape.VoxelShape
import net.minecraft.util.shape.VoxelShapes
import net.minecraft.world.BlockView
import net.minecraft.world.World
import net.shadowfacts.extrahoppers.block.base.BaseHopperBlock
import net.shadowfacts.extrahoppers.block.base.BlockWithEntity
/**
* @author shadowfacts
*/
class WoodHopperBlock: BaseHopperBlock<WoodHopperBlockEntity>(
FabricBlockSettings.of(Material.WOOD)
.strength(2f, 3f)
.sounds(BlockSoundGroup.WOOD)
.nonOpaque()
.build()
) {
companion object {
val ID = Identifier("extrahoppers", "wood_hopper")
}
override fun createBlockEntity(world: BlockView) = WoodHopperBlockEntity()
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(WoodHopperContainer.ID, player) { buf ->
buf.writeBlockPos(pos)
}
}
return ActionResult.SUCCESS
}
override fun onEntityCollision(state: BlockState, world: World, pos: BlockPos, entity: Entity) {
getBlockEntity(world, pos)?.also {
it.onEntityCollision(entity)
}
}
}