From dfa5627ddd546eef3f34621868c0b43f8f58da38 Mon Sep 17 00:00:00 2001 From: xtex Date: Fri, 28 Jul 2023 10:00:40 +0800 Subject: [PATCH] feat: reality stabler --- .../kotlin/quaedam/misc/reality/RSBlock.kt | 31 ++++++++++++++++++ .../quaedam/misc/reality/RSBlockEntity.kt | 18 +++++++++++ .../quaedam/misc/reality/RealityStabler.kt | 32 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt create mode 100644 common/src/main/kotlin/quaedam/misc/reality/RSBlockEntity.kt create mode 100644 common/src/main/kotlin/quaedam/misc/reality/RealityStabler.kt diff --git a/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt b/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt new file mode 100644 index 0000000..e94cef1 --- /dev/null +++ b/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt @@ -0,0 +1,31 @@ +package quaedam.misc.reality + +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.world.level.block.EntityBlock +import net.minecraft.world.level.block.HorizontalDirectionalBlock +import net.minecraft.world.level.block.SimpleWaterloggedBlock +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.properties.BlockStateProperties +import net.minecraft.world.level.material.MapColor + +object RSBlock : HorizontalDirectionalBlock( + Properties.of() + .noOcclusion() + .strength(3f) + .requiresCorrectToolForDrops() + .mapColor(MapColor.COLOR_CYAN) +), EntityBlock, SimpleWaterloggedBlock { + + init { + registerDefaultState( + defaultBlockState() + .setValue(FACING, Direction.EAST) + .setValue(BlockStateProperties.WATERLOGGED, false) + ) + } + + override fun newBlockEntity(pos: BlockPos, state: BlockState) = RSBlockEntity(pos, state) + +} \ No newline at end of file diff --git a/common/src/main/kotlin/quaedam/misc/reality/RSBlockEntity.kt b/common/src/main/kotlin/quaedam/misc/reality/RSBlockEntity.kt new file mode 100644 index 0000000..69dc3c8 --- /dev/null +++ b/common/src/main/kotlin/quaedam/misc/reality/RSBlockEntity.kt @@ -0,0 +1,18 @@ +package quaedam.misc.reality + +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 + +class RSBlockEntity(pos: BlockPos, state: BlockState) : + BlockEntity(RealityStabler.blockEntity.get(), pos, state) { + + override fun getUpdateTag(): CompoundTag = saveWithoutMetadata() + + override fun getUpdatePacket(): Packet = ClientboundBlockEntityDataPacket.create(this) + +} diff --git a/common/src/main/kotlin/quaedam/misc/reality/RealityStabler.kt b/common/src/main/kotlin/quaedam/misc/reality/RealityStabler.kt new file mode 100644 index 0000000..cfa3212 --- /dev/null +++ b/common/src/main/kotlin/quaedam/misc/reality/RealityStabler.kt @@ -0,0 +1,32 @@ +package quaedam.misc.reality + +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 RealityStabler { + + const val ID = "reality_stabler" + + val block = Quaedam.blocks.register(ID) { RSBlock }!! + + val item = Quaedam.items.register(ID) { + BlockItem( + RSBlock, Item.Properties() + .stacksTo(1) + .`arch$tab`(Quaedam.creativeModeTab) + ) + }!! + + val blockEntity = Quaedam.blockEntities.register(ID) { + BlockEntityType.Builder.of(::RSBlockEntity, block.get()).build(null) + }!! + + fun checkEffect(level: Level, pos: BlockPos) = level.getChunkAt(pos) + .blockEntities + .any { (_, v) -> v is RSBlockEntity } + +} \ No newline at end of file