Add wood hopper model/shape

This commit is contained in:
Shadowfacts 2020-03-27 22:50:11 -04:00
parent a1aef324e8
commit 3d305dd890
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
6 changed files with 164 additions and 3 deletions

View File

@ -1,8 +1,23 @@
package net.shadowfacts.extrahoppers.block.wood
import net.minecraft.block.Material
import net.minecraft.util.Identifier
import net.minecraft.block.*
import net.minecraft.block.entity.Hopper
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityContext
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemPlacementContext
import net.minecraft.item.ItemStack
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.BlockWithEntity
/**
@ -11,9 +26,90 @@ import net.shadowfacts.extrahoppers.block.base.BlockWithEntity
class WoodHopperBlock: BlockWithEntity<WoodHopperBlockEntity>(Settings.of(Material.WOOD)) {
companion object {
val ID = Identifier("extrahoppers", "wood_hopper")
val FACING = Properties.HOPPER_FACING
// todo: redstone support
// val ENABLED = Properties.ENABLED
val TOP_SHAPE = createCuboidShape(0.0, 10.0, 0.0, 16.0, 16.0, 16.0)
val MIDDLE_SHAPE = createCuboidShape(4.0, 4.0, 4.0, 12.0, 10.0, 12.0)
val OUTSIDE_SHAPE = VoxelShapes.union(MIDDLE_SHAPE, TOP_SHAPE)
val DEFAULT_SHAPE = VoxelShapes.combineAndSimplify(OUTSIDE_SHAPE, Hopper.INSIDE_SHAPE, BooleanBiFunction.ONLY_FIRST)
val DOWN_SHAPE = VoxelShapes.union(DEFAULT_SHAPE, createCuboidShape(6.0, 0.0, 6.0, 10.0, 4.0, 10.0))
val EAST_SHAPE = VoxelShapes.union(DEFAULT_SHAPE, createCuboidShape(12.0, 4.0, 6.0, 16.0, 8.0, 10.0))
val NORTH_SHAPE = VoxelShapes.union(DEFAULT_SHAPE, createCuboidShape(6.0, 4.0, 0.0, 10.0, 8.0, 4.0))
val SOUTH_SHAPE = VoxelShapes.union(DEFAULT_SHAPE, createCuboidShape(6.0, 4.0, 12.0, 10.0, 8.0, 16.0))
val WEST_SHAPE = VoxelShapes.union(DEFAULT_SHAPE, createCuboidShape(0.0, 4.0, 6.0, 4.0, 8.0, 10.0))
val DOWN_RAY_TRACE_SHAPE = Hopper.INSIDE_SHAPE
val EAST_RAY_TRACE_SHAPE = VoxelShapes.union(Hopper.INSIDE_SHAPE, createCuboidShape(12.0, 8.0, 6.0, 16.0, 10.0, 10.0))
val NORTH_RAY_TRACE_SHAPE = VoxelShapes.union(Hopper.INSIDE_SHAPE, createCuboidShape(6.0, 8.0, 0.0, 10.0, 10.0, 4.0))
val SOUTH_RAY_TRACE_SHAPE = VoxelShapes.union(Hopper.INSIDE_SHAPE, createCuboidShape(6.0, 8.0, 12.0, 10.0, 10.0, 16.0))
val WEST_RAY_TRACE_SHAPE = VoxelShapes.union(Hopper.INSIDE_SHAPE, createCuboidShape(0.0, 8.0, 6.0, 4.0, 10.0, 10.0))
}
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
builder.add(FACING)
}
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, entityContext: EntityContext): VoxelShape {
return when (state.get(FACING)) {
Direction.DOWN -> DOWN_SHAPE
Direction.NORTH -> NORTH_SHAPE
Direction.SOUTH -> SOUTH_SHAPE
Direction.WEST -> WEST_SHAPE
Direction.EAST -> EAST_SHAPE
else -> DEFAULT_SHAPE
}
}
override fun getRayTraceShape(state: BlockState, world: BlockView, pos: BlockPos): VoxelShape {
return when (state.get(FACING)) {
Direction.DOWN -> DOWN_RAY_TRACE_SHAPE
Direction.NORTH -> NORTH_RAY_TRACE_SHAPE
Direction.SOUTH -> SOUTH_RAY_TRACE_SHAPE
Direction.WEST -> WEST_RAY_TRACE_SHAPE
Direction.EAST -> EAST_RAY_TRACE_SHAPE
else -> Hopper.INSIDE_SHAPE
}
}
override fun getPlacementState(context: ItemPlacementContext): BlockState {
val hitFacing = context.side.opposite
val facing = if (hitFacing.axis == Direction.Axis.Y) Direction.DOWN else hitFacing
return defaultState.with(FACING, facing)
}
override fun createBlockEntity(world: BlockView): WoodHopperBlockEntity {
return WoodHopperBlockEntity()
}
}
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult): ActionResult {
// todo: container
return super.onUse(state, world, pos, player, hand, hitResult)
}
override fun onBlockRemoved(oldState: BlockState, world: World, pos: BlockPos, newState: BlockState, bl: Boolean) {
if (oldState.block != newState.block) {
getBlockEntity(world, pos)?.also {
// todo: spawn items
// ItemScatterer.spawn(world, pos, it)
world.updateHorizontalAdjacent(pos, this)
}
}
super.onBlockRemoved(oldState, world, pos, newState, bl)
}
override fun getRenderType(blockState: BlockState?): BlockRenderType {
return BlockRenderType.MODEL
}
override fun onEntityCollision(state: BlockState, world: World, pos: BlockPos, entity: Entity) {
getBlockEntity(world, pos)?.also {
// todo: handle entity collision
}
}
override fun canPlaceAtSide(blockState: BlockState?, blockView: BlockView?, blockPos: BlockPos?, blockPlacementEnvironment: BlockPlacementEnvironment?): Boolean {
return false
}
}

View File

@ -0,0 +1,9 @@
{
"variants": {
"facing=down": { "model": "extrahoppers:block/wood_hopper" },
"facing=north": { "model": "extrahoppers:block/wood_hopper_side" },
"facing=south": { "model": "extrahoppers:block/wood_hopper_side", "y": 180 },
"facing=west": { "model": "extrahoppers:block/wood_hopper_side", "y": 270 },
"facing=east": { "model": "extrahoppers:block/wood_hopper_side", "y": 90 }
}
}

View File

@ -0,0 +1,3 @@
{
"block.extrahoppers.wood_hopper": "Wooden Hopper"
}

View File

@ -0,0 +1,41 @@
{
"parent": "block/hopper",
"textures": {
"particle": "block/oak_planks",
"top": "block/oak_planks",
"side": "block/oak_planks",
"inside": "block/oak_planks"
},
"display": {
"gui": {
"rotation": [ 30, 225, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.625, 0.625, 0.625 ]
},
"ground": {
"rotation": [ 0, 0, 0 ],
"translation": [ 0, 3, 0],
"scale":[ 0.25, 0.25, 0.25 ]
},
"fixed": {
"rotation": [ 0, 0, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.5, 0.5, 0.5 ]
},
"thirdperson_righthand": {
"rotation": [ 75, 45, 0 ],
"translation": [ 0, 2.5, 0],
"scale": [ 0.375, 0.375, 0.375 ]
},
"firstperson_righthand": {
"rotation": [ 0, 45, 0 ],
"translation": [ 0, 0, 0 ],
"scale": [ 0.40, 0.40, 0.40 ]
},
"firstperson_lefthand": {
"rotation": [ 0, 225, 0 ],
"translation": [ 0, 0, 0 ],
"scale": [ 0.40, 0.40, 0.40 ]
}
}
}

View File

@ -0,0 +1,9 @@
{
"parent": "block/hopper_side",
"textures": {
"particle": "block/oak_planks",
"top": "block/oak_planks",
"side": "block/oak_planks",
"inside": "block/oak_planks"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "extrahoppers:block/wood_hopper"
}