feat: CTS block

This commit is contained in:
xtex 2023-07-27 11:32:37 +08:00
parent 849a88bbf6
commit c290984202
Signed by: xtex
GPG Key ID: B918086ED8045B91
6 changed files with 96 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import net.minecraft.world.item.CreativeModeTab
import net.minecraft.world.item.ItemStack
import org.slf4j.LoggerFactory
import quaedam.config.QuaedamConfig
import quaedam.misc.cts.ConstantTemporalSink
import quaedam.projection.ProjectionCommand
import quaedam.projection.ProjectionEffectType
import quaedam.projection.SimpleProjectionUpdate
@ -54,6 +55,7 @@ object Quaedam {
ProjectionCommand
SimpleProjectionUpdate
ProjectionShell
ConstantTemporalSink
creativeModeTabs.register()
items.register()

View File

@ -0,0 +1,15 @@
package quaedam.misc.cts
import net.minecraft.core.BlockPos
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.state.BlockState
object CTSBlock : Block(
Properties.of()
.lightLevel { 2 }
), EntityBlock {
override fun newBlockEntity(pos: BlockPos, state: BlockState) = CTSBlockEntity(pos, state)
}

View File

@ -0,0 +1,19 @@
package quaedam.misc.cts
import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.game.ClientGamePacketListener
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import quaedam.projector.Projector
class CTSBlockEntity(pos: BlockPos, state: BlockState) :
BlockEntity(Projector.blockEntity.get(), pos, state) {
override fun getUpdateTag(): CompoundTag = saveWithoutMetadata()
override fun getUpdatePacket(): Packet<ClientGamePacketListener> = ClientboundBlockEntityDataPacket.create(this)
}

View File

@ -0,0 +1,32 @@
package quaedam.misc.cts
import net.minecraft.core.BlockPos
import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.Item
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.entity.BlockEntityType
import quaedam.Quaedam
object ConstantTemporalSink {
const val ID = "cts"
val block = Quaedam.blocks.register(ID) { CTSBlock }!!
val item = Quaedam.items.register(ID) {
BlockItem(
CTSBlock, Item.Properties()
.stacksTo(1)
.`arch$tab`(Quaedam.creativeModeTab)
)
}!!
val blockEntity = Quaedam.blockEntities.register(ID) {
BlockEntityType.Builder.of(::CTSBlockEntity, block.get()).build(null)
}!!
fun checkEffect(level: Level, pos: BlockPos) = level.getChunkAt(pos)
.blockEntities
.any { (_, v) -> v is CTSBlockEntity }
}

View File

@ -26,6 +26,7 @@ import net.minecraft.world.entity.npc.InventoryCarrier
import net.minecraft.world.level.Level
import net.minecraft.world.level.ServerLevelAccessor
import quaedam.Quaedam
import quaedam.misc.cts.ConstantTemporalSink
import quaedam.projection.misc.SoundProjection
import quaedam.projection.swarm.ai.ProjectedPersonAI
import quaedam.projection.swarm.ai.ProjectedPersonNavigation
@ -177,7 +178,7 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
override fun checkDespawn() {
super.checkDespawn()
if (!checkProjectionEffect()) {
if (!checkProjectionEffect() && !ConstantTemporalSink.checkEffect(level(), blockPosition())) {
dropEquipment()
remove(RemovalReason.KILLED)
}
@ -253,4 +254,6 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
override fun getAmbientSoundInterval() = 80 - random.nextInt(700)
override fun isEffectiveAi() = super.isEffectiveAi() && checkProjectionEffect()
}

View File

@ -94,5 +94,29 @@
"type": "file"
}
]
},
"quaedam.projection.noise": {
"sounds": [
{
"name": "entity.villager.work_librarian",
"weight": 2,
"type": "event"
},
{
"name": "entity.villager.work_cleric",
"weight": 2,
"type": "event"
},
{
"name": "entity.villager.work_mason",
"weight": 2,
"type": "event"
},
{
"name": "entity.villager.work_shepherd",
"weight": 2,
"type": "event"
}
]
}
}