2021-03-03 03:20:25 +00:00
|
|
|
package net.shadowfacts.phycon.block.redstone_emitter
|
|
|
|
|
|
|
|
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
|
|
|
import net.minecraft.block.BlockState
|
|
|
|
import net.minecraft.block.Material
|
|
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
|
|
import net.minecraft.entity.player.PlayerInventory
|
|
|
|
import net.minecraft.network.PacketByteBuf
|
|
|
|
import net.minecraft.screen.ScreenHandler
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity
|
|
|
|
import net.minecraft.sound.BlockSoundGroup
|
|
|
|
import net.minecraft.text.Text
|
|
|
|
import net.minecraft.util.ActionResult
|
|
|
|
import net.minecraft.util.Hand
|
|
|
|
import net.minecraft.util.Identifier
|
|
|
|
import net.minecraft.util.hit.BlockHitResult
|
|
|
|
import net.minecraft.util.math.BlockPos
|
|
|
|
import net.minecraft.util.math.Direction
|
|
|
|
import net.minecraft.world.BlockView
|
|
|
|
import net.minecraft.world.World
|
|
|
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
|
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class RedstoneEmitterBlock: FaceDeviceBlock<RedstoneEmitterBlockEntity>(
|
|
|
|
Settings.of(Material.METAL)
|
|
|
|
.strength(1.5f)
|
|
|
|
.sounds(BlockSoundGroup.METAL)
|
|
|
|
) {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
val ID = Identifier(PhysicalConnectivity.MODID, "redstone_emitter")
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: don't just copy the redstone controller
|
|
|
|
override val faceThickness = 3.0
|
|
|
|
override val faceShapes = mapOf(
|
|
|
|
Direction.DOWN to createCuboidShape(0.0, 0.0, 0.0, 16.0, 3.0, 16.0),
|
|
|
|
Direction.UP to createCuboidShape(0.0, 13.0, 0.0, 16.0, 16.0, 16.0),
|
|
|
|
Direction.NORTH to createCuboidShape(0.0, 0.0, 0.0, 16.0, 16.0, 3.0),
|
|
|
|
Direction.SOUTH to createCuboidShape(0.0, 0.0, 13.0, 16.0, 16.0, 16.0),
|
|
|
|
Direction.WEST to createCuboidShape(0.0, 0.0, 0.0, 3.0, 16.0, 16.0),
|
|
|
|
Direction.EAST to createCuboidShape(13.0, 0.0, 0.0, 16.0, 16.0, 16.0)
|
|
|
|
)
|
|
|
|
|
2021-12-22 23:59:51 +00:00
|
|
|
override fun createBlockEntity(pos: BlockPos, state: BlockState) = RedstoneEmitterBlockEntity(pos, state)
|
2021-03-03 03:20:25 +00:00
|
|
|
|
|
|
|
override fun emitsRedstonePower(state: BlockState): Boolean {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getStrongRedstonePower(state: BlockState, world: BlockView, pos: BlockPos, receivingSide: Direction): Int {
|
|
|
|
return if (receivingSide.opposite == state[FACING]) {
|
|
|
|
getBlockEntity(world, pos)!!.cachedEmittedPower
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getWeakRedstonePower(state: BlockState, world: BlockView, pos: BlockPos, receivingSide: Direction): Int {
|
|
|
|
return getStrongRedstonePower(state, world, pos, receivingSide)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, result: BlockHitResult): ActionResult {
|
|
|
|
if (!world.isClient) {
|
|
|
|
val be = getBlockEntity(world, pos)!!
|
|
|
|
|
2021-12-22 23:59:51 +00:00
|
|
|
be.markUpdate()
|
2021-03-03 03:20:25 +00:00
|
|
|
|
|
|
|
val factory = object: ExtendedScreenHandlerFactory {
|
|
|
|
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
|
|
|
return RedstoneEmitterScreenHandler(syncId, playerInv, be)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getDisplayName() = this@RedstoneEmitterBlock.name
|
|
|
|
|
|
|
|
override fun writeScreenOpeningData(player: ServerPlayerEntity, buf: PacketByteBuf) {
|
|
|
|
buf.writeBlockPos(be.pos)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
player.openHandledScreen(factory)
|
|
|
|
}
|
|
|
|
return ActionResult.SUCCESS
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|