Physical models for bus/i/o

This commit is contained in:
DBotThePony 2022-05-16 16:09:59 +07:00
parent 8cabf8d295
commit ccb8c24ee9
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 220 additions and 92 deletions

View File

@ -51,6 +51,12 @@ public record BlockShape(SimpleCuboid ...shapes) {
if (dir == Direction.EAST) if (dir == Direction.EAST)
return rotateAroundY(Math.PI / 2d); 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; return this;
} }
@ -67,6 +73,12 @@ public record BlockShape(SimpleCuboid ...shapes) {
if (dir == Direction.EAST) if (dir == Direction.EAST)
return rotateAroundY(Math.PI / 2d); 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; return this;
} }

View File

@ -475,4 +475,26 @@ public class BlockShapes {
new SimpleCuboid(0.96875d, 0.0625d, 0.9375d, 1d, 0.3125d, 1d), 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) 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)
);
} }

View File

@ -184,101 +184,111 @@ class MatterCableBlock : CableBlock(
class StorageCableBlock : CableBlock( class StorageCableBlock : CableBlock(
Properties.of(Material.STONE, MaterialColor.METAL).requiresCorrectToolForDrops().strength(1.0f, 6.0f)), Properties.of(Material.STONE, MaterialColor.METAL).requiresCorrectToolForDrops().strength(1.0f, 6.0f)),
EntityBlock { EntityBlock {
private val CORE_SHAPE: VoxelShape = Shapes.box(
0.5 - 0.185, companion object {
0.5 - 0.185, 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,
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<VoxelShape> {
val shapes = ArrayList<VoxelShape>()
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 { private val shapes = getShapeForEachState {
val shapes = ArrayList<VoxelShape>() val shapes = getShapeFor(it)
val width = 0.185 var finalShape = shapes[0]
if (it.getValue(CONNECTION_SOUTH)) { for (i in 1 until shapes.size) {
shapes.add( finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR)
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 return@getShapeForEachState finalShape

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.EntityBlock 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.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.StateDefinition 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.addPreWorldTickerOnce
import ru.dbotthepony.mc.otm.block.entity.StorageBusBlockEntity import ru.dbotthepony.mc.otm.block.entity.StorageBusBlockEntity
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.unaryMinus import ru.dbotthepony.mc.otm.unaryMinus
class StorageBusBlock : RotatableMatteryBlock(), EntityBlock { class StorageBusBlock : RotatableMatteryBlock(), EntityBlock {
@ -58,6 +64,30 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock {
return BlockEntityTicker { _, _, _, tile -> if (tile is StorageBusBlockEntity) tile.tick() } 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( override fun neighborChanged(
state: BlockState, state: BlockState,
level: Level, level: Level,

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.block
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.item.context.BlockPlaceContext
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.EntityBlock 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.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.StateDefinition 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.addPreWorldTickerOnce
import ru.dbotthepony.mc.otm.block.entity.StorageExporterBlockEntity import ru.dbotthepony.mc.otm.block.entity.StorageExporterBlockEntity
import ru.dbotthepony.mc.otm.block.entity.StorageImporterBlockEntity import ru.dbotthepony.mc.otm.block.entity.StorageImporterBlockEntity
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.unaryMinus import ru.dbotthepony.mc.otm.unaryMinus
class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock { class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
@ -59,6 +65,30 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) 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( override fun neighborChanged(
state: BlockState, state: BlockState,
level: Level, level: Level,
@ -124,6 +154,30 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock {
return super.getStateForPlacement(context)?.setValue(FACING_FULL, -context.clickedFace) 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( override fun neighborChanged(
state: BlockState, state: BlockState,
level: Level, level: Level,