feat: /제작대, /workbench 명령어 추가 - 제작대 블록 없이 제작대 GUI 열기
This commit is contained in:
parent
695bc79ca4
commit
d0d8d0650f
3 changed files with 72 additions and 0 deletions
|
|
@ -33,5 +33,6 @@ class Essentials(modEventBus: IEventBus) {
|
||||||
NeoForge.EVENT_BUS.register(NicknameCommand)
|
NeoForge.EVENT_BUS.register(NicknameCommand)
|
||||||
NeoForge.EVENT_BUS.register(HeadCommand)
|
NeoForge.EVENT_BUS.register(HeadCommand)
|
||||||
NeoForge.EVENT_BUS.register(HelpCommand)
|
NeoForge.EVENT_BUS.register(HelpCommand)
|
||||||
|
NeoForge.EVENT_BUS.register(WorkbenchCommand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,11 @@ object HelpCommand {
|
||||||
sendCategory(player, "머리", ChatFormatting.GOLD)
|
sendCategory(player, "머리", ChatFormatting.GOLD)
|
||||||
sendCommand(player, "/머리", "내 머리 아이템 받기")
|
sendCommand(player, "/머리", "내 머리 아이템 받기")
|
||||||
sendCommand(player, "/머리 <닉네임>", "해당 플레이어 머리 받기")
|
sendCommand(player, "/머리 <닉네임>", "해당 플레이어 머리 받기")
|
||||||
|
player.sendSystemMessage(Component.empty())
|
||||||
|
|
||||||
|
// 제작대
|
||||||
|
sendCategory(player, "제작대", ChatFormatting.WHITE)
|
||||||
|
sendCommand(player, "/제작대", "제작대 열기")
|
||||||
|
|
||||||
val footer =
|
val footer =
|
||||||
Component.literal("═══════════════════════════════").withStyle {
|
Component.literal("═══════════════════════════════").withStyle {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.beemer.essentials.command
|
||||||
|
|
||||||
|
import java.util.Optional
|
||||||
|
import java.util.function.BiFunction
|
||||||
|
import net.minecraft.ChatFormatting
|
||||||
|
import net.minecraft.commands.Commands
|
||||||
|
import net.minecraft.core.BlockPos
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.server.level.ServerPlayer
|
||||||
|
import net.minecraft.world.SimpleMenuProvider
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.inventory.ContainerLevelAccess
|
||||||
|
import net.minecraft.world.inventory.CraftingMenu
|
||||||
|
import net.minecraft.world.level.Level
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent
|
||||||
|
import net.neoforged.neoforge.event.RegisterCommandsEvent
|
||||||
|
|
||||||
|
object WorkbenchCommand {
|
||||||
|
@SubscribeEvent
|
||||||
|
fun onRegisterCommands(event: RegisterCommandsEvent) {
|
||||||
|
// /제작대, /workbench - 제작대 GUI 열기
|
||||||
|
listOf("제작대", "workbench").forEach { command ->
|
||||||
|
event.dispatcher.register(
|
||||||
|
Commands.literal(command).executes { context ->
|
||||||
|
val player = context.source.entity as? ServerPlayer
|
||||||
|
if (player == null) {
|
||||||
|
context.source.sendFailure(
|
||||||
|
Component.literal("플레이어만 사용할 수 있는 명령어입니다.")
|
||||||
|
.withStyle(ChatFormatting.RED)
|
||||||
|
)
|
||||||
|
return@executes 0
|
||||||
|
}
|
||||||
|
|
||||||
|
openWorkbench(player)
|
||||||
|
1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 항상 유효한 ContainerLevelAccess 생성 */
|
||||||
|
private fun createAlwaysValidAccess(level: Level, pos: BlockPos): ContainerLevelAccess {
|
||||||
|
return object : ContainerLevelAccess {
|
||||||
|
override fun <T : Any> evaluate(function: BiFunction<Level, BlockPos, T>): Optional<T> {
|
||||||
|
return Optional.ofNullable(function.apply(level, pos))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 플레이어에게 제작대 GUI 열기 */
|
||||||
|
private fun openWorkbench(player: ServerPlayer) {
|
||||||
|
val access = createAlwaysValidAccess(player.level(), player.blockPosition())
|
||||||
|
|
||||||
|
player.openMenu(
|
||||||
|
SimpleMenuProvider(
|
||||||
|
{ containerId, inventory, _ ->
|
||||||
|
object : CraftingMenu(containerId, inventory, access) {
|
||||||
|
// stillValid를 오버라이드하여 항상 true 반환 (거리 제한 없음)
|
||||||
|
override fun stillValid(player: Player): Boolean = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Component.translatable("container.crafting")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue