Move gravitation stabilizer rotation on placement to block
This commit is contained in:
parent
c9d5397a4f
commit
71aaf98bb1
@ -1,6 +1,8 @@
|
||||
package ru.dbotthepony.mc.otm.block
|
||||
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.SectionPos
|
||||
import net.minecraft.world.item.context.BlockPlaceContext
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.EntityBlock
|
||||
@ -13,7 +15,10 @@ import net.minecraft.world.level.material.Material
|
||||
import net.minecraft.world.level.material.MaterialColor
|
||||
import ru.dbotthepony.mc.otm.Registry
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityGravitationStabilizer
|
||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityBlackHole
|
||||
import ru.dbotthepony.mc.otm.block.entity.worker.WorkerState
|
||||
import ru.dbotthepony.mc.otm.core.plus
|
||||
import ru.dbotthepony.mc.otm.core.times
|
||||
|
||||
class BlockGravitationStabilizer : BlockMatteryRotatable(Properties.of(Material.STONE, MaterialColor.COLOR_BLUE).requiresCorrectToolForDrops().strength(3f, 600.0f)), EntityBlock {
|
||||
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
||||
@ -37,4 +42,28 @@ class BlockGravitationStabilizer : BlockMatteryRotatable(Properties.of(Material.
|
||||
super.createBlockStateDefinition(builder)
|
||||
builder.add(WorkerState.SEMI_WORKER_STATE)
|
||||
}
|
||||
|
||||
override fun getStateForPlacement(context: BlockPlaceContext): BlockState? {
|
||||
var state = super.getStateForPlacement(context) ?: return null
|
||||
val blockPos = context.clickedPos
|
||||
val level = context.level
|
||||
|
||||
for (face in FACING_FULL.possibleValues) {
|
||||
val dir = face.normal
|
||||
|
||||
for (i in 1 ..BlockEntityGravitationStabilizer.RANGE) {
|
||||
val pos = blockPos + dir * i
|
||||
val chunk = level.chunkSource.getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z)) ?: continue
|
||||
val getState = chunk.getBlockState(pos)
|
||||
|
||||
if (!getState.isAir) {
|
||||
if (chunk.getBlockEntity(pos) is BlockEntityBlackHole) {
|
||||
state = state.setValue(FACING_FULL, face)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
@ -62,31 +62,6 @@ class BlockEntityGravitationStabilizer(p_155229_: BlockPos, p_155230_: BlockStat
|
||||
blackHole?.stabilizerDetached(this)
|
||||
}
|
||||
|
||||
override fun setLevel(level: Level) {
|
||||
super.setLevel(level)
|
||||
|
||||
if (!level.isClientSide) {
|
||||
OverdriveThatMatters.tickOnce(level) {
|
||||
for (face in BlockMatteryRotatable.FACING_FULL.possibleValues) {
|
||||
val dir = face.normal
|
||||
|
||||
for (i in 1 .. RANGE) {
|
||||
val pos = blockPos + dir * i
|
||||
val chunk = level.chunkSource.getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z)) ?: continue
|
||||
val state = chunk.getBlockState(pos)
|
||||
|
||||
if (!state.isAir) {
|
||||
if (chunk.getBlockEntity(pos) is BlockEntityBlackHole) {
|
||||
level.setBlock(blockPos, blockState.setValue(BlockMatteryRotatable.FACING_FULL, face), Block.UPDATE_ALL)
|
||||
return@tickOnce
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val RANGE = 64
|
||||
private val NAME = TranslatableComponent("block.overdrive_that_matters.gravitation_stabilizer")
|
||||
|
Loading…
Reference in New Issue
Block a user