Use getShapeForEachState

This commit is contained in:
DBotThePony 2023-01-30 16:05:26 +07:00
parent 643ca83851
commit ba90c60cd2
Signed by: DBot
GPG Key ID: DCC23B5715498507
19 changed files with 156 additions and 326 deletions

View File

@ -18,7 +18,7 @@ class EngineBlock : RotatableMatteryBlock(Properties.of(Material.METAL, DyeColor
}
private val shapes = getShapeForEachState {
BlockShapes.ENGINE.rotateFromNorth(it[rotationProperty].front).computeShape()
BlockShapes.ENGINE.rotateFromNorth(it[rotationProperty]).computeShape()
}
override fun getShape(

View File

@ -18,6 +18,7 @@ import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -51,35 +52,23 @@ class MatterBottlerBlock : RotatableMatteryBlock(), EntityBlock {
.setValue(SLOT_PROPERTIES[2], false)
}
private val shapes = getShapeForEachState { BlockShapes.MATTER_BOTTLER.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
return shapes[state]!!
}
companion object {
private val SHAPES: List<VoxelShape>
val SLOT_PROPERTIES = arrayOf(
BooleanProperty.create("bottle_0"),
BooleanProperty.create("bottle_1"),
BooleanProperty.create("bottle_2")
)
init {
val def = BlockShapes.MATTER_BOTTLER.computeShape()
SHAPES = listOf(
def,
def,
def,
BlockShapes.MATTER_BOTTLER.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.MATTER_BOTTLER.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.MATTER_BOTTLER.rotateFromSouth(Direction.EAST).computeShape()
)
}
}
}

View File

@ -14,7 +14,7 @@ import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.tech.BatteryBankBlock
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.shapes.BlockShapes
class MatterCapacitorBankBlock : RotatableMatteryBlock(), EntityBlock {
@ -32,33 +32,19 @@ class MatterCapacitorBankBlock : RotatableMatteryBlock(), EntityBlock {
}
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
builder.add(*BatteryBankBlock.BATTERY_SLOTS_PROPS)
BatteryBankBlock.BATTERY_SLOTS_PROPS.forEach(builder::add)
super.createBlockStateDefinition(builder)
}
private val shapes = getShapeForEachState { BlockShapes.MATTER_CAPACITOR_BANK.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: List<VoxelShape>
init {
val def = BlockShapes.MATTER_CAPACITOR_BANK.computeShape()
SHAPES = listOf(
def,
def,
def,
BlockShapes.MATTER_CAPACITOR_BANK.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.MATTER_CAPACITOR_BANK.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.MATTER_CAPACITOR_BANK.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}

View File

@ -18,6 +18,7 @@ import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -45,25 +46,15 @@ class MatterDecomposerBlock : RotatableMatteryBlock(), EntityBlock {
builder.add(WorkerState.WORKER_STATE)
}
private val shapes = getShapeForEachState { BlockShapes.MATTER_DECOMPOSER.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val def = BlockShapes.MATTER_DECOMPOSER.computeShape()
private val SHAPES: List<VoxelShape> = listOf(
def,
def,
def,
BlockShapes.MATTER_DECOMPOSER.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.MATTER_DECOMPOSER.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.MATTER_DECOMPOSER.rotateFromSouth(Direction.EAST).computeShape()
)
return shapes[state]!!
}
}

View File

@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -41,29 +42,15 @@ class MatterRecyclerBlock : RotatableMatteryBlock(), EntityBlock {
return BlockEntityTicker { _, _, _, tile -> if (tile is MatterRecyclerBlockEntity) tile.tick() }
}
private val shapes = getShapeForEachState { BlockShapes.MATTER_RECYCLER.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.MATTER_RECYCLER.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.MATTER_RECYCLER.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.MATTER_RECYCLER.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.MATTER_RECYCLER.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}

View File

@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.matter.MatterReplicatorBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -41,29 +42,15 @@ class MatterReplicatorBlock : RotatableMatteryBlock(), EntityBlock {
builder.add(WorkerState.WORKER_STATE)
}
private val shapes = getShapeForEachState { BlockShapes.MATTER_REPLICATOR.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.MATTER_REPLICATOR.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.MATTER_REPLICATOR.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.MATTER_REPLICATOR.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.MATTER_REPLICATOR.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}

View File

@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.matter.MatterScannerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -41,29 +42,15 @@ class MatterScannerBlock : RotatableMatteryBlock(), EntityBlock {
builder.add(WorkerState.WORKER_STATE)
}
private val shapes = getShapeForEachState { BlockShapes.MATTER_SCANNER.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.MATTER_SCANNER.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.MATTER_SCANNER.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.MATTER_SCANNER.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.MATTER_SCANNER.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}

View File

@ -16,6 +16,7 @@ import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.matter.PatternStorageBlockEntity
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -57,13 +58,16 @@ class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock {
super.onRemove(oldBlockState, level, blockPos, newBlockState, movedByPiston)
}
private val shapes = getShapeForEachState { BlockShapes.PATTERN_STORAGE.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
return shapes[state]!!
}
companion object {
@ -77,20 +81,5 @@ class PatternStorageBlock : RotatableMatteryBlock(), EntityBlock {
BooleanProperty.create("disk_6") as BooleanProperty,
BooleanProperty.create("disk_7") as BooleanProperty
)
private val SHAPES: List<VoxelShape>
init {
val def = BlockShapes.PATTERN_STORAGE.computeShape()
SHAPES = listOf(
def,
def,
def,
BlockShapes.PATTERN_STORAGE.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.PATTERN_STORAGE.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.PATTERN_STORAGE.rotateFromSouth(Direction.EAST).computeShape()
)
}
}
}

View File

@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.DriveRackBlockEntity
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -49,25 +50,15 @@ class DriveRackBlock : RotatableMatteryBlock(), EntityBlock {
MatteryPoweredBlockEntity.appendHoverText(p_49816_, p_49817_, p_49818_, p_49819_)
}
private val shapes = getShapeForEachState { BlockShapes.DRIVE_RACK.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val def = BlockShapes.DRIVE_RACK.computeShape()
private val SHAPES: List<VoxelShape> = listOf(
def,
def,
def,
BlockShapes.DRIVE_RACK.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.DRIVE_RACK.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.DRIVE_RACK.rotateFromSouth(Direction.EAST).computeShape()
)
return shapes[state]!!
}
}

View File

@ -23,6 +23,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.DriveViewerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -64,30 +65,19 @@ class DriveViewerBlock : RotatableMatteryBlock(), EntityBlock {
return super.getStateForPlacement(context)!!.setValue(DRIVE_PRESENT, false)
}
private val shapes = getShapeForEachState { BlockShapes.DRIVE_VIEWER.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
return shapes[state]!!
}
companion object {
val DRIVE_PRESENT: BooleanProperty = BooleanProperty.create("drive")
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.DRIVE_VIEWER.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.DRIVE_VIEWER.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.DRIVE_VIEWER.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.DRIVE_VIEWER.rotateFromSouth(Direction.EAST).computeShape()
)
}
}
}

View File

@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorBlockEntity
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -49,25 +50,15 @@ class ItemMonitorBlock : RotatableMatteryBlock(), EntityBlock {
MatteryPoweredBlockEntity.appendHoverText(p_49816_, p_49817_, p_49818_, p_49819_)
}
private val shapes = getShapeForEachState { BlockShapes.ITEM_MONITOR.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val def = BlockShapes.ITEM_MONITOR.computeShape()
private val SHAPES: List<VoxelShape> = listOf(
def,
def,
def,
BlockShapes.ITEM_MONITOR.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.ITEM_MONITOR.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.ITEM_MONITOR.rotateFromSouth(Direction.EAST).computeShape()
)
return shapes[state]!!
}
}

View File

@ -24,9 +24,11 @@ import ru.dbotthepony.mc.otm.block.StorageCableBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.StorageBusBlockEntity
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotation
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.facingTwo
import ru.dbotthepony.mc.otm.core.math.rotationTwo
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
import ru.dbotthepony.mc.otm.core.math.unaryMinus
@ -98,7 +100,7 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock {
finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR)
}
finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_BUS.rotateFromNorth(it.facingTwo).computeShape(), BooleanOp.OR)
finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_BUS.rotateFromNorth(it[rotationProperty]).computeShape(), BooleanOp.OR)
return@getShapeForEachState finalShape
}
@ -110,7 +112,7 @@ class StorageBusBlock : RotatableMatteryBlock(), EntityBlock {
p_60557_: BlockPos,
p_60558_: CollisionContext
): VoxelShape {
return shapes[p_60555_] ?: BlockShapes.STORAGE_BUS.computeShape()
return shapes[p_60555_]!!
}
@Suppress("OVERRIDE_DEPRECATION")

View File

@ -25,6 +25,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.StorageExporterBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.StorageImporterBlockEntity
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotation
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.facingTwo
@ -99,7 +100,7 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR)
}
finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_IMPORTER.rotateFromNorth(it.facingTwo).computeShape(), BooleanOp.OR)
finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_IMPORTER.rotateFromNorth(it[rotationProperty]).computeShape(), BooleanOp.OR)
return@getShapeForEachState finalShape
}
@ -111,7 +112,7 @@ class StorageImporterBlock : RotatableMatteryBlock(), EntityBlock {
p_60557_: BlockPos,
p_60558_: CollisionContext
): VoxelShape {
return shapes[p_60555_] ?: BlockShapes.STORAGE_BUS.computeShape()
return shapes[p_60555_]!!
}
@Suppress("OVERRIDE_DEPRECATION")
@ -203,7 +204,7 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock {
finalShape = Shapes.joinUnoptimized(finalShape, shapes[i], BooleanOp.OR)
}
finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_EXPORTER.rotateFromNorth(it.facingTwo).computeShape(), BooleanOp.OR)
finalShape = Shapes.joinUnoptimized(finalShape, BlockShapes.STORAGE_EXPORTER.rotateFromNorth(it[rotationProperty]).computeShape(), BooleanOp.OR)
return@getShapeForEachState finalShape
}
@ -215,7 +216,7 @@ class StorageExporterBlock : RotatableMatteryBlock(), EntityBlock {
p_60557_: BlockPos,
p_60558_: CollisionContext
): VoxelShape {
return shapes[p_60555_] ?: BlockShapes.STORAGE_BUS.computeShape()
return shapes[p_60555_]!!
}
@Suppress("OVERRIDE_DEPRECATION")

View File

@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -49,29 +50,15 @@ class StoragePowerSupplierBlock : RotatableMatteryBlock(), EntityBlock {
MatteryPoweredBlockEntity.appendHoverText(p_49816_, p_49817_, p_49818_, p_49819_)
}
private val shapes = getShapeForEachState { BlockShapes.STORAGE_POWER_SUPPLIER.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.STORAGE_POWER_SUPPLIER.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.STORAGE_POWER_SUPPLIER.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.STORAGE_POWER_SUPPLIER.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.STORAGE_POWER_SUPPLIER.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.block.tech
import com.google.common.collect.ImmutableList
import net.minecraft.MethodsReturnNonnullByDefault
import javax.annotation.ParametersAreNonnullByDefault
import net.minecraft.world.level.block.EntityBlock
@ -11,7 +12,6 @@ import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.state.StateDefinition
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
@ -19,7 +19,7 @@ import net.minecraft.world.level.block.Block
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.oncePre
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -48,7 +48,7 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock {
}
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
builder.add(*BATTERY_SLOTS_PROPS)
BATTERY_SLOTS_PROPS.forEach(builder::add)
super.createBlockStateDefinition(builder)
}
@ -56,13 +56,16 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock {
return BatteryBankBlockEntity(blockPos, blockState)
}
private val shapes = getShapeForEachState { BlockShapes.BATTERY_BANK.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
return shapes[state]!!
}
override fun faceToPlayer(context: BlockPlaceContext): Boolean {
@ -83,7 +86,7 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock {
}
companion object {
val BATTERY_SLOTS_PROPS = arrayOf(
val BATTERY_SLOTS_PROPS: ImmutableList<BooleanProperty> = ImmutableList.of(
BooleanProperty.create("battery_0") as BooleanProperty,
BooleanProperty.create("battery_1") as BooleanProperty,
BooleanProperty.create("battery_2") as BooleanProperty,
@ -97,20 +100,5 @@ class BatteryBankBlock : RotatableMatteryBlock(), EntityBlock {
BooleanProperty.create("battery_10") as BooleanProperty,
BooleanProperty.create("battery_11") as BooleanProperty,
)
private val SHAPES: List<VoxelShape>
init {
val def = BlockShapes.BATTERY_BANK.computeShape()
SHAPES = java.util.List.of(
def,
def,
def,
BlockShapes.BATTERY_BANK.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.BATTERY_BANK.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.BATTERY_BANK.rotateFromSouth(Direction.EAST).computeShape()
)
}
}
}

View File

@ -27,6 +27,7 @@ import ru.dbotthepony.mc.otm.capability.energy.GeneratorEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl
import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.core.nbt.map
import ru.dbotthepony.mc.otm.oncePre
@ -95,25 +96,15 @@ class ChemicalGeneratorBlock : RotatableMatteryBlock(), EntityBlock {
}
}
private val shapes = getShapeForEachState { BlockShapes.CHEMICAL_GENERATOR.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val def = BlockShapes.CHEMICAL_GENERATOR.computeShape()
private val SHAPES: List<VoxelShape> = listOf(
def,
def,
def,
BlockShapes.CHEMICAL_GENERATOR.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.CHEMICAL_GENERATOR.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.CHEMICAL_GENERATOR.rotateFromSouth(Direction.EAST).computeShape()
)
return shapes[state]!!
}
}

View File

@ -15,6 +15,7 @@ import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -36,29 +37,15 @@ class EnergyServoBlock : RotatableMatteryBlock(Properties.of(Material.METAL, Mat
return null
}
private val shapes = getShapeForEachState { BlockShapes.ENERGY_SERVO.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.ENERGY_SERVO.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.ENERGY_SERVO.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.ENERGY_SERVO.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.ENERGY_SERVO.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}

View File

@ -30,6 +30,7 @@ import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.core.math.minus
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.rotationOne
import ru.dbotthepony.mc.otm.once
import ru.dbotthepony.mc.otm.registry.MBlocks
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -86,15 +87,13 @@ class PhantomAttractorBlock : RotatableMatteryBlock(Properties.of(Material.METAL
}
}
private val shapes by lazy {
getShapeForEachState {
val shape = when (it[BlockStateProperties.DOUBLE_BLOCK_HALF]!!) {
DoubleBlockHalf.UPPER -> BlockShapes.PHANTOM_ATTRACTOR_TOP.moveY(-1.0)
DoubleBlockHalf.LOWER -> BlockShapes.PHANTOM_ATTRACTOR_BOTTOM
}
shape.rotateFromSouth(it.facingOne).computeShape()
private val shapes = getShapeForEachState {
val shape = when (it[BlockStateProperties.DOUBLE_BLOCK_HALF]!!) {
DoubleBlockHalf.UPPER -> BlockShapes.PHANTOM_ATTRACTOR_TOP.moveY(-1.0)
DoubleBlockHalf.LOWER -> BlockShapes.PHANTOM_ATTRACTOR_BOTTOM
}
shape.rotateFromSouth(it[rotationProperty]).computeShape()
}
override fun getShape(

View File

@ -20,6 +20,7 @@ import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity
import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.facingOne
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.shapes.BlockShapes
@ -55,29 +56,15 @@ class PlatePressBlock(properties: Properties = DEFAULT_PROPERTIES) : RotatableMa
MatteryWorkerBlockEntity.appendHoverText(p_49816_, p_49817_, p_49818_, p_49819_)
}
private val shapes = getShapeForEachState { BlockShapes.PLATE_PRESS_IDLE.rotateFromSouth(it[rotationProperty]).computeShape() }
@Suppress("override_deprecation")
override fun getShape(
p_60555_: BlockState,
p_60556_: BlockGetter,
p_60557_: BlockPos,
p_60558_: CollisionContext
state: BlockState,
blockGetter: BlockGetter,
pos: BlockPos,
context: CollisionContext
): VoxelShape {
return SHAPES[p_60555_.facingOne.ordinal]
}
companion object {
private val SHAPES: Array<VoxelShape>
init {
val def = BlockShapes.PLATE_PRESS_IDLE.computeShape()
SHAPES = arrayOf(
def,
def,
def,
BlockShapes.PLATE_PRESS_IDLE.rotateFromSouth(Direction.NORTH).computeShape(),
BlockShapes.PLATE_PRESS_IDLE.rotateFromSouth(Direction.WEST).computeShape(),
BlockShapes.PLATE_PRESS_IDLE.rotateFromSouth(Direction.EAST).computeShape()
)
}
return shapes[state]!!
}
}