Make computer terminal behave like redstone button
This commit is contained in:
parent
e6387d7d5b
commit
9683e53115
@ -58,6 +58,9 @@ private fun decoratives(provider: MatteryLanguageProvider) {
|
||||
}
|
||||
|
||||
with(provider.english) {
|
||||
misc("computer_terminal_tooltip", "Can be used as Redstone button, except it sends signal to block behind it, not under")
|
||||
misc("decorative", "Decorative")
|
||||
|
||||
add(MItems.CARGO_CRATE_MINECARTS[null]!!, "Minecart with Cargo Crate")
|
||||
add(MEntityTypes.CARGO_CRATE_MINECARTS[null]!!, "Minecart with Cargo Crate")
|
||||
|
||||
|
@ -67,6 +67,9 @@ private fun decoratives(provider: MatteryLanguageProvider) {
|
||||
}
|
||||
|
||||
with(provider.russian) {
|
||||
misc("computer_terminal_tooltip", "Может быть использован как кнопка, с оговоркой что он посылает сигнал блоку сзади, а не под ним")
|
||||
misc("decorative", "Элемент декора")
|
||||
|
||||
add(MItems.CARGO_CRATE_MINECARTS[null]!!, "Вагонетка с грузовым ящиком")
|
||||
add(MEntityTypes.CARGO_CRATE_MINECARTS[null]!!, "Вагонетка с грузовым ящиком")
|
||||
|
||||
|
@ -50,10 +50,10 @@ fun Block.getShapeForEachState(properties: List<Property<*>>, fn: (BlockState) -
|
||||
val builder = Object2ObjectArrayMap<BlockState, Supplier<VoxelShape>>()
|
||||
|
||||
if (properties.isEmpty()) {
|
||||
val shape = Util.backgroundExecutor().submit(Callable { fn(stateDefinition.possibleStates.first()) })
|
||||
val shape = Util.backgroundExecutor().submit(Callable { fn(stateDefinition.possibleStates.first()) }).asSupplier()
|
||||
|
||||
for (state in stateDefinition.possibleStates) {
|
||||
builder[state] = shape.asSupplier()
|
||||
builder[state] = shape
|
||||
}
|
||||
} else {
|
||||
val cache = Object2ObjectArrayMap<List<Any>, Supplier<VoxelShape>>()
|
||||
|
@ -51,9 +51,7 @@ open class RotatableMatteryBlock(properties: Properties = DEFAULT_PROPERTIES) :
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
override fun rotate(blockState: BlockState, rotation: Rotation): BlockState {
|
||||
@Suppress("DEPRECATION")
|
||||
return super.rotate(blockState, rotation).setValue(rotationProperty, blockState[rotationProperty].rotate(rotation))
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,121 @@
|
||||
package ru.dbotthepony.mc.otm.block.decorative
|
||||
|
||||
import net.minecraft.ChatFormatting
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.item.DyeColor
|
||||
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.SoundType
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import net.minecraft.world.level.block.state.StateDefinition
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties
|
||||
import net.minecraft.world.level.gameevent.GameEvent
|
||||
import net.minecraft.world.level.material.MapColor
|
||||
import net.minecraft.world.phys.BlockHitResult
|
||||
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.getShapeForEachState
|
||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||
import ru.dbotthepony.mc.otm.core.get
|
||||
import ru.dbotthepony.mc.otm.core.math.plus
|
||||
import ru.dbotthepony.mc.otm.core.set
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
||||
|
||||
class ComputerTerminalBlock(val color: DyeColor?) : RotatableMatteryBlock(
|
||||
Properties.of()
|
||||
.mapColor(color?.mapColor ?: MapColor.COLOR_LIGHT_BLUE)
|
||||
.sound(SoundType.METAL)
|
||||
.explosionResistance(15f)
|
||||
.destroyTime(1.5f)
|
||||
) {
|
||||
private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.COMPUTER_TERMINAL.rotateFromNorth(it[rotationProperty]).computeShape() }
|
||||
|
||||
init {
|
||||
registerDefaultState(defaultBlockState().set(BlockStateProperties.POWERED, false))
|
||||
}
|
||||
|
||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
||||
super.createBlockStateDefinition(builder)
|
||||
builder.add(BlockStateProperties.POWERED)
|
||||
}
|
||||
|
||||
override fun getSignal(p_60483_: BlockState, p_60484_: BlockGetter, p_60485_: BlockPos, p_60486_: Direction): Int {
|
||||
return if (p_60483_[BlockStateProperties.POWERED]) 15 else 0
|
||||
}
|
||||
|
||||
override fun getDirectSignal(
|
||||
p_60559_: BlockState,
|
||||
p_60560_: BlockGetter,
|
||||
p_60561_: BlockPos,
|
||||
p_60562_: Direction
|
||||
): Int {
|
||||
// weird that p_60559_[rotationProperty].front should be used and not p_60559_[rotationProperty].back
|
||||
// minecraft engine shenanigans
|
||||
return if (p_60559_[BlockStateProperties.POWERED] && p_60559_[rotationProperty].front == p_60562_) 15 else 0
|
||||
}
|
||||
|
||||
override fun isSignalSource(p_60571_: BlockState): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun updateNeighbours(blockState: BlockState, blockPos: BlockPos, level: Level) {
|
||||
level.updateNeighborsAt(blockPos, this)
|
||||
level.updateNeighborsAt(blockPos + blockState[rotationProperty].back, this)
|
||||
}
|
||||
|
||||
override fun useWithoutItem(
|
||||
blockState: BlockState,
|
||||
level: Level,
|
||||
blockPos: BlockPos,
|
||||
ply: Player,
|
||||
blockHitResult: BlockHitResult
|
||||
): InteractionResult {
|
||||
if (blockState[BlockStateProperties.POWERED]) {
|
||||
return InteractionResult.CONSUME
|
||||
} else {
|
||||
level.setBlock(blockPos, blockState.set(BlockStateProperties.POWERED, true), UPDATE_ALL)
|
||||
updateNeighbours(blockState, blockPos, level)
|
||||
level.scheduleTick(blockPos, this, 40)
|
||||
level.playSound(ply, blockPos, SoundEvents.STONE_BUTTON_CLICK_ON, SoundSource.BLOCKS, 1f, 1f)
|
||||
level.gameEvent(ply, GameEvent.BLOCK_ACTIVATE, blockPos)
|
||||
return InteractionResult.sidedSuccess(level.isClientSide)
|
||||
}
|
||||
}
|
||||
|
||||
override fun tick(blockState: BlockState, level: ServerLevel, blockPos: BlockPos, random: RandomSource) {
|
||||
super.tick(blockState, level, blockPos, random)
|
||||
|
||||
if (blockState[BlockStateProperties.POWERED]) {
|
||||
level.setBlock(blockPos, blockState.set(BlockStateProperties.POWERED, false), UPDATE_ALL)
|
||||
level.playSound(null, blockPos, SoundEvents.STONE_BUTTON_CLICK_OFF, SoundSource.BLOCKS, 1f, 1f)
|
||||
level.gameEvent(null, GameEvent.BLOCK_DEACTIVATE, blockPos)
|
||||
updateNeighbours(blockState, blockPos, level)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
tooltips.add(TranslatableComponent("otm.decorative").withStyle(ChatFormatting.GRAY))
|
||||
tooltips.add(TranslatableComponent("otm.computer_terminal_tooltip").withStyle(ChatFormatting.GRAY))
|
||||
tooltips.painted(color)
|
||||
}
|
||||
|
||||
override fun getShape(
|
||||
state: BlockState,
|
||||
blockGetter: BlockGetter,
|
||||
pos: BlockPos,
|
||||
context: CollisionContext
|
||||
): VoxelShape {
|
||||
return shapes[state]!!
|
||||
}
|
||||
}
|
@ -248,8 +248,7 @@ operator fun StateHolder<*, *>.get(property: BlockRotationFreedom): BlockRotatio
|
||||
}
|
||||
|
||||
operator fun <S : StateHolder<*, *>, T : Comparable<T>> S.set(property: Property<T>, value: T): S {
|
||||
setValue(property, value)
|
||||
return this
|
||||
return setValue(property, value) as S
|
||||
}
|
||||
|
||||
fun <T> List<T>.toImmutableList(): List<T> {
|
||||
|
@ -32,6 +32,7 @@ import ru.dbotthepony.mc.otm.android.AndroidFeatureType
|
||||
import ru.dbotthepony.mc.otm.android.feature.EnderTeleporterFeature
|
||||
import ru.dbotthepony.mc.otm.android.feature.NanobotsArmorFeature
|
||||
import ru.dbotthepony.mc.otm.block.decorative.CargoCrateBlock
|
||||
import ru.dbotthepony.mc.otm.block.decorative.ComputerTerminalBlock
|
||||
import ru.dbotthepony.mc.otm.block.decorative.StarChairBlock
|
||||
import ru.dbotthepony.mc.otm.block.decorative.TritaniumPressurePlate
|
||||
import ru.dbotthepony.mc.otm.capability.matteryEnergy
|
||||
@ -103,14 +104,7 @@ object MRegistry : IBlockItemRegistryAcceptor {
|
||||
.destroyTime(2.5f)
|
||||
}.also { decorativeBlocks.add(it) }
|
||||
|
||||
val COMPUTER_TERMINAL = DecorativeBlock.rotatable("computer_terminal", BlockShapes.COMPUTER_TERMINAL, BlockRotationFreedom.HORIZONTAL) {
|
||||
BlockBehaviour.Properties.of()
|
||||
.mapColor(it?.mapColor ?: MapColor.COLOR_LIGHT_BLUE)
|
||||
.sound(SoundType.METAL)
|
||||
.explosionResistance(15f)
|
||||
.destroyTime(1.5f)
|
||||
}.also { decorativeBlocks.add(it) }
|
||||
|
||||
val COMPUTER_TERMINAL = DecorativeBlock("computer_terminal", ::ComputerTerminalBlock).also { decorativeBlocks.add(it) }
|
||||
val STAR_CHAIR = DecorativeBlock("star_chair", ::StarChairBlock).also { decorativeBlocks.add(it) }
|
||||
|
||||
val TRITANIUM_STAIRS = DecorativeBlock(MNames.TRITANIUM_STAIRS) {
|
||||
|
Loading…
Reference in New Issue
Block a user