diff --git a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShape.java b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShape.java index 9c9c168f6..95590fe3b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShape.java +++ b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShape.java @@ -51,6 +51,12 @@ public record BlockShape(SimpleCuboid ...shapes) { if (dir == Direction.EAST) return rotateAroundY(Math.PI / 2d); + if (dir == Direction.UP) + return rotateAroundX(Math.PI / 2d); + + if (dir == Direction.DOWN) + return rotateAroundX(-Math.PI / 2d); + return this; } @@ -67,6 +73,12 @@ public record BlockShape(SimpleCuboid ...shapes) { if (dir == Direction.EAST) return rotateAroundY(Math.PI / 2d); + if (dir == Direction.UP) + return rotateAroundX(-Math.PI / 2d); + + if (dir == Direction.DOWN) + return rotateAroundX(Math.PI / 2d); + return this; } diff --git a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java index b873312a2..8907f4a08 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java +++ b/src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java @@ -475,4 +475,26 @@ public class BlockShapes { new SimpleCuboid(0.96875d, 0.0625d, 0.9375d, 1d, 0.3125d, 1d), new SimpleCuboid(0.0625d, 0.0625d, 0.6875d, 0.9375d, 0.3125d, 0.9375d) ); + + public static final BlockShape STORAGE_BUS = new BlockShape( + new SimpleCuboid(0.125d, 0.125d, 0d, 0.875d, 0.875d, 0.125d), + new SimpleCuboid(0.25d, 0.25d, 0.125d, 0.75d, 0.75d, 0.3125d), + new SimpleCuboid(0.3125d, 0.3125d, 0.25d, 0.6875d, 0.6875d, 0.5d), + new SimpleCuboid(0.4375d, 0.6875d, 0.125d, 0.5625d, 0.8125d, 0.375d), + new SimpleCuboid(0.4375d, 0.1875d, 0.125d, 0.5625d, 0.3125d, 0.375d), + new SimpleCuboid(0.1875d, 0.4375d, 0.125d, 0.3125d, 0.5625d, 0.375d), + new SimpleCuboid(0.6875d, 0.4375d, 0.125d, 0.8125d, 0.5625d, 0.375d) + ); + + public static final BlockShape STORAGE_IMPORTER = new BlockShape( + new SimpleCuboid(0.125d, 0.125d, 0d, 0.875d, 0.875d, 0.125d), + new SimpleCuboid(0.25d, 0.25d, 0.125d, 0.75d, 0.75d, 0.3125d), + new SimpleCuboid(0.3125d, 0.3125d, 0.25d, 0.6875d, 0.6875d, 0.5d) + ); + + public static final BlockShape STORAGE_EXPORTER = new BlockShape( + new SimpleCuboid(0.1875d, 0.1875d, 0d, 0.8125d, 0.8125d, 0.125d), + new SimpleCuboid(0.25d, 0.25d, 0.125d, 0.75d, 0.75d, 0.3125d), + new SimpleCuboid(0.3125d, 0.3125d, 0.25d, 0.6875d, 0.6875d, 0.5d) + ); } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt index d434bab0b..d48726a54 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/Cables.kt @@ -184,101 +184,111 @@ 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 - ) + + companion object { + 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 const val width = 0.185 + + fun getShapeFor(it: BlockState): MutableList { + val shapes = ArrayList() + + 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 + ) + ) + } + + shapes.add(CORE_SHAPE) + return shapes + } + } private val shapes = getShapeForEachState { - val shapes = ArrayList() - val width = 0.185 + val shapes = getShapeFor(it) + var finalShape = shapes[0] - 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) + for (i in 1 until shapes.size) { + finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) } return@getShapeForEachState finalShape diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageBusBlock.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageBusBlock.kt index 094eb8d2c..81a09eb67 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageBusBlock.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageBusBlock.kt @@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block import net.minecraft.core.BlockPos import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.EntityBlock @@ -10,9 +11,14 @@ import net.minecraft.world.level.block.entity.BlockEntityTicker import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.phys.shapes.BooleanOp +import net.minecraft.world.phys.shapes.CollisionContext +import net.minecraft.world.phys.shapes.Shapes +import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.addPreWorldTickerOnce import ru.dbotthepony.mc.otm.block.entity.StorageBusBlockEntity import ru.dbotthepony.mc.otm.registry.MBlockEntities +import ru.dbotthepony.mc.otm.shapes.BlockShapes import ru.dbotthepony.mc.otm.unaryMinus class StorageBusBlock : RotatableMatteryBlock(), EntityBlock { @@ -58,6 +64,30 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock { return BlockEntityTicker { _, _, _, tile -> if (tile is StorageBusBlockEntity) tile.tick() } } + private val shapes = getShapeForEachState { + val shapes = StorageCableBlock.getShapeFor(it) + var finalShape = shapes[0] + + for (i in 1 until shapes.size) { + finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) + } + + finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_BUS.rotateInv(it.getValue(FACING_FULL)).computeShape(), 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_] ?: BlockShapes.STORAGE_BUS.computeShape() + } + + @Suppress("OVERRIDE_DEPRECATION") override fun neighborChanged( state: BlockState, level: Level, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageInterfaces.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageInterfaces.kt index ddba587e8..d1c636bae 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageInterfaces.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/StorageInterfaces.kt @@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block import net.minecraft.core.BlockPos import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.EntityBlock @@ -10,10 +11,15 @@ import net.minecraft.world.level.block.entity.BlockEntityTicker import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition +import net.minecraft.world.phys.shapes.BooleanOp +import net.minecraft.world.phys.shapes.CollisionContext +import net.minecraft.world.phys.shapes.Shapes +import net.minecraft.world.phys.shapes.VoxelShape import ru.dbotthepony.mc.otm.addPreWorldTickerOnce import ru.dbotthepony.mc.otm.block.entity.StorageExporterBlockEntity import ru.dbotthepony.mc.otm.block.entity.StorageImporterBlockEntity import ru.dbotthepony.mc.otm.registry.MBlockEntities +import ru.dbotthepony.mc.otm.shapes.BlockShapes import ru.dbotthepony.mc.otm.unaryMinus class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock { @@ -59,6 +65,30 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock { return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) } + private val shapes = getShapeForEachState { + val shapes = StorageCableBlock.getShapeFor(it) + var finalShape = shapes[0] + + for (i in 1 until shapes.size) { + finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) + } + + finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_IMPORTER.rotateInv(it.getValue(FACING_FULL)).computeShape(), 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_] ?: BlockShapes.STORAGE_BUS.computeShape() + } + + @Suppress("OVERRIDE_DEPRECATION") override fun neighborChanged( state: BlockState, level: Level, @@ -124,6 +154,30 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock { return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) } + private val shapes = getShapeForEachState { + val shapes = StorageCableBlock.getShapeFor(it) + var finalShape = shapes[0] + + for (i in 1 until shapes.size) { + finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR) + } + + finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_EXPORTER.rotateInv(it.getValue(FACING_FULL)).computeShape(), 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_] ?: BlockShapes.STORAGE_BUS.computeShape() + } + + @Suppress("OVERRIDE_DEPRECATION") override fun neighborChanged( state: BlockState, level: Level,