feat: right-click to cycle projection effect radius

This commit is contained in:
xtex 2023-08-01 14:55:35 +08:00
parent c6edaac2e1
commit f588d3bc72
Signed by: xtex
GPG Key ID: B918086ED8045B91
5 changed files with 22 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package quaedam.projector
import net.minecraft.core.BlockPos
import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerLevel
import net.minecraft.util.RandomSource
import net.minecraft.world.InteractionHand
@ -15,6 +16,8 @@ import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.material.MapColor
import net.minecraft.world.level.material.PushReaction
import net.minecraft.world.phys.BlockHitResult
import quaedam.shell.ProjectionShellItem
import quaedam.utils.sendBlockUpdated
object ProjectorBlock : Block(Properties.of()
.jumpFactor(0.8f)
@ -41,6 +44,21 @@ object ProjectorBlock : Block(Properties.of()
interactionHand: InteractionHand,
blockHitResult: BlockHitResult
): InteractionResult {
if (player.getItemInHand(interactionHand).item == ProjectionShellItem) {
if (!level.isClientSide) {
val entity = level.getBlockEntity(blockPos) as ProjectorBlockEntity
var newRadius = entity.effectRadius + 1
if (newRadius > Projector.currentEffectRadius) {
newRadius = 0
}
entity.updateEffectArea(newRadius)
entity.setChanged()
entity.sendBlockUpdated()
checkUpdate(level, blockPos)
player.sendSystemMessage(Component.translatable("quaedam.projector.radius_updated", newRadius))
}
return InteractionResult.sidedSuccess(level.isClientSide)
}
checkUpdate(level, blockPos)
return InteractionResult.PASS
}

View File

@ -70,7 +70,7 @@ class ProjectorBlockEntity(pos: BlockPos, state: BlockState) :
updateEffects(effects, notify = false)
}
private fun updateEffectArea(radius: Int) {
fun updateEffectArea(radius: Int) {
effectRadius = radius
val chunk = ChunkPos(SectionPos.blockToSectionCoord(blockPos.x), SectionPos.blockToSectionCoord(blockPos.z))
val minChunk = ChunkPos(chunk.x - radius, chunk.z - radius)

View File

@ -13,6 +13,7 @@
"item.quaedam.projection_shell": "Projection Shell",
"item.quaedam.iron_copper_metal": "Copper-iron Alloy",
"item.quaedam.projection_metal": "Projection Metal",
"quaedam.projector.radius_updated": "Current effect radius: %s",
"quaedam.screen.projection_shell": "Projection Shell",
"quaedam.screen.projection_shell.lock_revoked": "Timeout! Connection Lost",
"quaedam.screen.projection_shell.lock_failed": "Permission denied!",

View File

@ -13,6 +13,7 @@
"item.quaedam.projection_shell": "投影操作面板",
"item.quaedam.iron_copper_metal": "铜铁合金",
"item.quaedam.projection_metal": "投影金属",
"quaedam.projector.radius_updated": "当前效果半径:%s",
"quaedam.screen.projection_shell": "投影操作",
"quaedam.screen.projection_shell.lock_revoked": "超时!连接丢失",
"quaedam.screen.projection_shell.lock_failed": "正被使用",

View File

@ -13,6 +13,7 @@
"item.quaedam.projection_shell": "投射滥权终端",
"item.quaedam.iron_copper_metal": "有点生锈的铁锭",
"item.quaedam.projection_metal": "投影Metal©",
"quaedam.projector.radius_updated": "现在乱七八糟的效果能碰到的范围:%s",
"quaedam.screen.projection_shell": "控制面板",
"quaedam.screen.projection_shell.lock_revoked": "土豆熟了",
"quaedam.screen.projection_shell.lock_failed": "宁配吗?",