refactor: rename cyber instrument -> smart instrument

This commit is contained in:
xtex 2023-07-30 10:26:39 +08:00
parent fe5eeb0364
commit 96c48fa0db
Signed by: xtex
GPG Key ID: B918086ED8045B91
7 changed files with 25 additions and 26 deletions

View File

@ -35,7 +35,7 @@ object MusicProjection {
}!! }!!
init { init {
CyberInstrument SmartInstrument
} }
} }

View File

@ -12,7 +12,6 @@ import net.minecraft.world.InteractionResult
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.BlockItem import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.minecraft.world.item.context.BlockPlaceContext
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
@ -31,26 +30,26 @@ import quaedam.projector.Projector
import quaedam.utils.getChunksNearby import quaedam.utils.getChunksNearby
import quaedam.utils.sendBlockUpdated import quaedam.utils.sendBlockUpdated
object CyberInstrument { object SmartInstrument {
const val ID = "cyber_instrument" const val ID = "smart_instrument"
val block = Quaedam.blocks.register(ID) { CyberInstrumentBlock }!! val block = Quaedam.blocks.register(ID) { SmartInstrumentBlock }!!
val item = Quaedam.items.register(ID) { val item = Quaedam.items.register(ID) {
BlockItem( BlockItem(
CyberInstrumentBlock, Item.Properties() SmartInstrumentBlock, Item.Properties()
.`arch$tab`(Quaedam.creativeModeTab) .`arch$tab`(Quaedam.creativeModeTab)
) )
}!! }!!
val blockEntity = Quaedam.blockEntities.register(ID) { val blockEntity = Quaedam.blockEntities.register(ID) {
BlockEntityType.Builder.of(::CyberInstrumentBlockEntity, block.get()).build(null) BlockEntityType.Builder.of(::SmartInstrumentBlockEntity, block.get()).build(null)
}!! }!!
} }
object CyberInstrumentBlock : Block( object SmartInstrumentBlock : Block(
Properties.of() Properties.of()
.strength(2.7f) .strength(2.7f)
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
@ -65,7 +64,7 @@ object CyberInstrumentBlock : Block(
) )
} }
override fun newBlockEntity(pos: BlockPos, state: BlockState) = CyberInstrumentBlockEntity(pos, state) override fun newBlockEntity(pos: BlockPos, state: BlockState) = SmartInstrumentBlockEntity(pos, state)
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) { override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
super.createBlockStateDefinition(builder) super.createBlockStateDefinition(builder)
@ -107,7 +106,7 @@ object CyberInstrumentBlock : Block(
random: RandomSource random: RandomSource
) { ) {
if (Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()).isNotEmpty()) { if (Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()).isNotEmpty()) {
val entity = level.getBlockEntity(pos) as CyberInstrumentBlockEntity val entity = level.getBlockEntity(pos) as SmartInstrumentBlockEntity
if (entity.player == null) { if (entity.player == null) {
entity.startMusic() entity.startMusic()
} }
@ -126,7 +125,7 @@ object CyberInstrumentBlock : Block(
if (Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()).isNotEmpty() if (Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()).isNotEmpty()
|| CausalityAnchor.checkEffect(level, pos) || CausalityAnchor.checkEffect(level, pos)
) { ) {
val entity = level.getBlockEntity(pos) as CyberInstrumentBlockEntity val entity = level.getBlockEntity(pos) as SmartInstrumentBlockEntity
if (entity.player == null) { if (entity.player == null) {
entity.startMusic() entity.startMusic()
} }
@ -141,14 +140,14 @@ object CyberInstrumentBlock : Block(
blockEntityType: BlockEntityType<T> blockEntityType: BlockEntityType<T>
): BlockEntityTicker<T> { ): BlockEntityTicker<T> {
return BlockEntityTicker { _, _, _, entity -> return BlockEntityTicker { _, _, _, entity ->
(entity as? CyberInstrumentBlockEntity)?.tick() (entity as? SmartInstrumentBlockEntity)?.tick()
} }
} }
} }
class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) : class SmartInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
BlockEntity(CyberInstrument.blockEntity.get(), pos, state) { BlockEntity(SmartInstrument.blockEntity.get(), pos, state) {
companion object { companion object {
const val TAG_MUSIC = "Music" const val TAG_MUSIC = "Music"
@ -188,12 +187,12 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
level!!.getChunksNearby(blockPos, 1) level!!.getChunksNearby(blockPos, 1)
.flatMap { .flatMap {
it.blockEntities it.blockEntities
.filterValues { entity -> entity is CyberInstrumentBlockEntity } .filterValues { entity -> entity is SmartInstrumentBlockEntity }
.filterKeys { pos -> pos.distSqr(blockPos) < 100 } .filterKeys { pos -> pos.distSqr(blockPos) < 100 }
.values .values
} }
.filterNot { it == this } .filterNot { it == this }
.filterIsInstance<CyberInstrumentBlockEntity>() .filterIsInstance<SmartInstrumentBlockEntity>()
.forEach { it.startMusic(force = true, synced = true) } .forEach { it.startMusic(force = true, synced = true) }
} }
} }

View File

@ -1,7 +0,0 @@
{
"variants": {
"": {
"model": "quaedam:block/cyber_instrument"
}
}
}

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "quaedam:block/smart_instrument"
}
}
}

View File

@ -1,3 +0,0 @@
{
"parent": "quaedam:block/cyber_instrument"
}

View File

@ -0,0 +1,3 @@
{
"parent": "quaedam:block/smart_instrument"
}