Storage cable now has proper collision box
This commit is contained in:
parent
d6e90e4679
commit
c67d0a54ca
@ -1,3 +1,6 @@
|
||||
|
||||
@file:Suppress("LeakingThis")
|
||||
|
||||
package ru.dbotthepony.mc.otm.block
|
||||
|
||||
import net.minecraft.core.BlockPos
|
||||
@ -18,90 +21,6 @@ import ru.dbotthepony.mc.otm.block.entity.MatterCableBlockEntity
|
||||
import ru.dbotthepony.mc.otm.block.entity.StorageCableBlockEntity
|
||||
|
||||
abstract class CableBlock(properties: Properties) : Block(properties) {
|
||||
private val shapes = getShapeForEachState {
|
||||
val shapes = ArrayList<VoxelShape>()
|
||||
|
||||
if (it.getValue(CONNECTION_SOUTH)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.65,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15, 1.0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_NORTH)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15, 0.0,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15,
|
||||
0.35
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_DOWN)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - 0.15, 0.0,
|
||||
0.5 - 0.15,
|
||||
0.5 + 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 + 0.15
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_UP)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 + 0.15, 1.0,
|
||||
0.5 + 0.15
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_EAST)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.65,
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15, 1.0,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15
|
||||
)
|
||||
)
|
||||
}
|
||||
if (it.getValue(CONNECTION_WEST)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.0,
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.35,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
var finalShape = CORE_SHAPE
|
||||
|
||||
for (add_shape in shapes) {
|
||||
finalShape = Shapes.joinUnoptimized(finalShape, add_shape, BooleanOp.OR)
|
||||
}
|
||||
|
||||
return@getShapeForEachState finalShape
|
||||
}
|
||||
|
||||
init {
|
||||
registerDefaultState(defaultBlockState()
|
||||
.setValue(CONNECTION_SOUTH, false)
|
||||
@ -112,16 +31,6 @@ abstract class CableBlock(properties: Properties) : Block(properties) {
|
||||
.setValue(CONNECTION_DOWN, false))
|
||||
}
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
override fun getShape(
|
||||
p_60555_: BlockState,
|
||||
p_60556_: BlockGetter,
|
||||
p_60557_: BlockPos,
|
||||
p_60558_: CollisionContext
|
||||
): VoxelShape {
|
||||
return shapes[p_60555_] ?: CORE_SHAPE
|
||||
}
|
||||
|
||||
override fun hasDynamicShape() = true
|
||||
|
||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
||||
@ -136,15 +45,6 @@ abstract class CableBlock(properties: Properties) : Block(properties) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
protected val CORE_SHAPE: VoxelShape = Shapes.box(
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15
|
||||
)
|
||||
|
||||
val CONNECTION_SOUTH: BooleanProperty = BooleanProperty.create("connect_south")
|
||||
val CONNECTION_WEST: BooleanProperty = BooleanProperty.create("connect_west")
|
||||
val CONNECTION_EAST: BooleanProperty = BooleanProperty.create("connect_east")
|
||||
@ -166,6 +66,115 @@ abstract class CableBlock(properties: Properties) : Block(properties) {
|
||||
class MatterCableBlock : CableBlock(
|
||||
Properties.of(Material.STONE, MaterialColor.METAL).requiresCorrectToolForDrops().strength(1.0f, 6.0f)),
|
||||
EntityBlock {
|
||||
private val CORE_SHAPE: VoxelShape = Shapes.box(
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 - 0.15,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15,
|
||||
0.5 + 0.15
|
||||
)
|
||||
|
||||
private val shapes = getShapeForEachState {
|
||||
val shapes = ArrayList<VoxelShape>()
|
||||
val width = 0.15
|
||||
|
||||
if (it.getValue(CONNECTION_SOUTH)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
0.5 + width,
|
||||
0.5 + width,
|
||||
1.0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_NORTH)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.0,
|
||||
0.5 + width,
|
||||
0.5 + width,
|
||||
0.5 - width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_DOWN)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.0,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
0.5 - width,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_UP)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
1.0,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_EAST)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 + width,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
1.0,
|
||||
0.5 + width,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_WEST)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.0,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
var finalShape = CORE_SHAPE
|
||||
|
||||
for (add_shape in shapes) {
|
||||
finalShape = Shapes.joinUnoptimized(finalShape, add_shape, BooleanOp.OR)
|
||||
}
|
||||
|
||||
return@getShapeForEachState finalShape
|
||||
}
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
override fun getShape(
|
||||
p_60555_: BlockState,
|
||||
p_60556_: BlockGetter,
|
||||
p_60557_: BlockPos,
|
||||
p_60558_: CollisionContext
|
||||
): VoxelShape {
|
||||
return shapes[p_60555_] ?: CORE_SHAPE
|
||||
}
|
||||
|
||||
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
|
||||
return MatterCableBlockEntity(blockPos, blockState)
|
||||
@ -175,6 +184,115 @@ class MatterCableBlock : CableBlock(
|
||||
class StorageCableBlock : CableBlock(
|
||||
Properties.of(Material.STONE, MaterialColor.METAL).requiresCorrectToolForDrops().strength(1.0f, 6.0f)),
|
||||
EntityBlock {
|
||||
private val CORE_SHAPE: VoxelShape = Shapes.box(
|
||||
0.5 - 0.185,
|
||||
0.5 - 0.185,
|
||||
0.5 - 0.185,
|
||||
0.5 + 0.185,
|
||||
0.5 + 0.185,
|
||||
0.5 + 0.185
|
||||
)
|
||||
|
||||
private val shapes = getShapeForEachState {
|
||||
val shapes = ArrayList<VoxelShape>()
|
||||
val width = 0.185
|
||||
|
||||
if (it.getValue(CONNECTION_SOUTH)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
0.5 + width,
|
||||
0.5 + width,
|
||||
1.0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_NORTH)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.0,
|
||||
0.5 + width,
|
||||
0.5 + width,
|
||||
0.5 - width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_DOWN)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.0,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
0.5 - width,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_UP)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
1.0,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_EAST)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.5 + width,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
1.0,
|
||||
0.5 + width,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (it.getValue(CONNECTION_WEST)) {
|
||||
shapes.add(
|
||||
Shapes.box(
|
||||
0.0,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 - width,
|
||||
0.5 + width,
|
||||
0.5 + width
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
var finalShape = CORE_SHAPE
|
||||
|
||||
for (add_shape in shapes) {
|
||||
finalShape = Shapes.joinUnoptimized(finalShape, add_shape, BooleanOp.OR)
|
||||
}
|
||||
|
||||
return@getShapeForEachState finalShape
|
||||
}
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
override fun getShape(
|
||||
p_60555_: BlockState,
|
||||
p_60556_: BlockGetter,
|
||||
p_60557_: BlockPos,
|
||||
p_60558_: CollisionContext
|
||||
): VoxelShape {
|
||||
return shapes[p_60555_] ?: CORE_SHAPE
|
||||
}
|
||||
|
||||
override fun newBlockEntity(blockPos: BlockPos, blockState: BlockState): BlockEntity {
|
||||
return StorageCableBlockEntity(blockPos, blockState)
|
||||
|
Loading…
Reference in New Issue
Block a user