This commit is contained in:
@@ -3,6 +3,7 @@ package gamer.noir.curseenc.command
|
|||||||
import com.mojang.brigadier.CommandDispatcher
|
import com.mojang.brigadier.CommandDispatcher
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType
|
import com.mojang.brigadier.arguments.StringArgumentType
|
||||||
import com.mojang.brigadier.context.CommandContext
|
import com.mojang.brigadier.context.CommandContext
|
||||||
|
import gamer.noir.curseenc.CurseOfEienNoChi
|
||||||
import gamer.noir.curseenc.data.AttachmentsServer
|
import gamer.noir.curseenc.data.AttachmentsServer
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
||||||
import net.minecraft.commands.CommandBuildContext
|
import net.minecraft.commands.CommandBuildContext
|
||||||
@@ -10,6 +11,7 @@ import net.minecraft.commands.CommandSourceStack
|
|||||||
import net.minecraft.commands.Commands
|
import net.minecraft.commands.Commands
|
||||||
import net.minecraft.commands.Commands.CommandSelection
|
import net.minecraft.commands.Commands.CommandSelection
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
|
|
||||||
object ModCommands {
|
object ModCommands {
|
||||||
@@ -21,35 +23,76 @@ object ModCommands {
|
|||||||
val player = context.source?.player
|
val player = context.source?.player
|
||||||
val Power = StringArgumentType.getString(context, "Power")
|
val Power = StringArgumentType.getString(context, "Power")
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.setAttached(AttachmentsServer.EXEMPLE,"$Power")
|
val powerList = player.getAttachedOrCreate(AttachmentsServer.Powers)
|
||||||
context.getSource()!!.sendSuccess( { Component.literal("Power set to $Power") }, false)
|
if (powerList.contains(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID ,Power))) {
|
||||||
|
|
||||||
|
context.getSource()!!.sendSuccess( { Component.literal("$Power Existe déjà ") }, false)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val newList = powerList.plus(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID,Power))
|
||||||
|
player.setAttached(AttachmentsServer.Powers,newList)
|
||||||
|
context.getSource()!!.sendSuccess({ Component.literal("$Power A été ajouté") }, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun executePowerRemove(context: CommandContext<CommandSourceStack?>): Int {
|
private fun executePowerRemove(context: CommandContext<CommandSourceStack?>): Int {
|
||||||
context.getSource()!!.sendSuccess( { Component.literal("Power !!!") }, false)
|
val player = context.source?.player
|
||||||
|
val Power = StringArgumentType.getString(context, "Power")
|
||||||
|
if (player != null) {
|
||||||
|
val powerList = player.getAttachedOrCreate(AttachmentsServer.Powers)
|
||||||
|
if (powerList.contains(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID ,Power))) {
|
||||||
|
val newList = powerList.minus(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID,Power))
|
||||||
|
player.setAttached(AttachmentsServer.Powers,newList)
|
||||||
|
context.getSource()!!.sendSuccess( { Component.literal("$Power a été révoqué") }, false)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
context.getSource()!!.sendSuccess({ Component.literal("Tu ne possèdes pas $Power") }, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun executePowerQuary(context: CommandContext<CommandSourceStack?>): Int {
|
private fun executePowerQuary(context: CommandContext<CommandSourceStack?>): Int {
|
||||||
val player = context.source?.player
|
val player = context.source?.player
|
||||||
if (player != null && player.hasAttached(AttachmentsServer.EXEMPLE)) {
|
if (player != null && player.hasAttached(AttachmentsServer.Powers)) {
|
||||||
val Power = player.getAttached(AttachmentsServer.EXEMPLE)
|
val Power = player.getAttached(AttachmentsServer.Powers)
|
||||||
context.getSource()!!.sendSuccess( { Component.literal("Power is $Power") }, false)
|
context.getSource()!!.sendSuccess( { Component.literal("La liste de vos pouvoirs est $Power") }, false)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
context.getSource()!!.sendSuccess( { Component.literal("nop") }, false)
|
context.getSource()!!.sendSuccess( { Component.literal("nop") }, false)
|
||||||
}
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun executePowerQuaryTyped(context: CommandContext<CommandSourceStack?>): Int {
|
||||||
|
val player = context.source?.player
|
||||||
|
val Power = StringArgumentType.getString(context, "Power")
|
||||||
|
if (player != null && player.hasAttached(AttachmentsServer.Powers)) {
|
||||||
|
val powerList = player.getAttachedOrCreate(AttachmentsServer.Powers)
|
||||||
|
if (powerList.contains(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID ,Power))) {
|
||||||
|
context.getSource()!!.sendSuccess( { Component.literal("Vous possédez $Power") }, false)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
context.getSource()!!.sendSuccess( { Component.literal("Tu ne possèdes pas $Power") }, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
context.getSource()!!.sendSuccess( { Component.literal("nop") }, false)
|
||||||
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val argument_power = Commands.argument("Power", StringArgumentType.string()).suggests { context, builder ->
|
val argument_power = Commands.argument("Power", StringArgumentType.string()).suggests { context, builder ->
|
||||||
builder.suggest("Night_vision")
|
builder.suggest("night_vision")
|
||||||
.suggest("Hyper_speed")
|
.suggest("hyper_speed")
|
||||||
.suggest("Bat_mod")
|
.suggest("bat_mod")
|
||||||
.suggest("...")
|
.suggest("...")
|
||||||
builder.buildFuture()
|
builder.buildFuture()
|
||||||
}
|
}
|
||||||
@@ -71,8 +114,9 @@ object ModCommands {
|
|||||||
.executes(ModCommands::executePowerRemove)))
|
.executes(ModCommands::executePowerRemove)))
|
||||||
|
|
||||||
.then(Commands.literal("quary")
|
.then(Commands.literal("quary")
|
||||||
|
.executes(ModCommands::executePowerQuary)
|
||||||
.then(argument_power
|
.then(argument_power
|
||||||
.executes(ModCommands::executePowerQuary)))
|
.executes(ModCommands::executePowerQuaryTyped)))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.mojang.serialization.Codec
|
|||||||
import gamer.noir.curseenc.CurseOfEienNoChi
|
import gamer.noir.curseenc.CurseOfEienNoChi
|
||||||
import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry
|
import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry
|
||||||
import net.fabricmc.fabric.api.attachment.v1.AttachmentSyncPredicate
|
import net.fabricmc.fabric.api.attachment.v1.AttachmentSyncPredicate
|
||||||
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.codec.ByteBufCodecs
|
import net.minecraft.network.codec.ByteBufCodecs
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
|
|
||||||
@@ -13,4 +14,10 @@ object AttachmentsServer {
|
|||||||
builder -> builder.initializer { "" }.syncWith(ByteBufCodecs.STRING_UTF8, AttachmentSyncPredicate.all()).persistent(
|
builder -> builder.initializer { "" }.syncWith(ByteBufCodecs.STRING_UTF8, AttachmentSyncPredicate.all()).persistent(
|
||||||
Codec.STRING).copyOnDeath()
|
Codec.STRING).copyOnDeath()
|
||||||
}
|
}
|
||||||
|
var Powers = AttachmentRegistry.create<List<ResourceLocation>>(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID,"powers")) {
|
||||||
|
builder -> builder.initializer { listOf() }
|
||||||
|
.syncWith(ResourceLocation.STREAM_CODEC.apply(ByteBufCodecs.list()), AttachmentSyncPredicate.all())
|
||||||
|
.persistent(ResourceLocation.CODEC.listOf())
|
||||||
|
.copyOnDeath()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user