From d962d38ba71a2e207496510657c36a45bc63a248 Mon Sep 17 00:00:00 2001 From: InsertSoda <72355883+InsertSoda@users.noreply.github.com> Date: Sun, 23 Jun 2024 00:02:30 +0200 Subject: [PATCH] Summon command TODO: Make custom identifier argument type --- build.gradle | 2 +- gradle.properties | 2 +- .../craterchat/commands/SummonCommand.java | 76 +++++++++++++++++++ .../craterchat/impl/PluginImpl.java | 3 +- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/insertsoda/craterchat/commands/SummonCommand.java diff --git a/build.gradle b/build.gradle index 26a1cce..6b2822a 100644 --- a/build.gradle +++ b/build.gradle @@ -72,7 +72,7 @@ dependencies { // Cosmic Quilt internal "dev.crmodders:cosmicquilt:${cosmic_quilt_version}" // Modmenu - internal "dev.crmodders:modmenu:${modmenu_version}" + //internal "dev.crmodders:modmenu:${modmenu_version}" internal "com.mojang:brigadier:1.0.18" diff --git a/gradle.properties b/gradle.properties index cb4571a..a6b5540 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ id=craterchat # Dependency Versions - cosmic_reach_version=0.1.33 + cosmic_reach_version=0.1.37 cosmic_quilt_version=2.0.2 modmenu_version=1.0.3 # fluxapi_version=0.5.8r2 diff --git a/src/main/java/com/insertsoda/craterchat/commands/SummonCommand.java b/src/main/java/com/insertsoda/craterchat/commands/SummonCommand.java new file mode 100644 index 0000000..8bbffa1 --- /dev/null +++ b/src/main/java/com/insertsoda/craterchat/commands/SummonCommand.java @@ -0,0 +1,76 @@ +package com.insertsoda.craterchat.commands; + +import com.insertsoda.craterchat.CraterChat; +import com.insertsoda.craterchat.api.v1.Command; +import com.insertsoda.craterchat.api.v1.CommandManager; +import com.insertsoda.craterchat.api.v1.CommandSource; +import com.insertsoda.craterchat.api.v1.arguments.types.RelativeFloatType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import finalforeach.cosmicreach.entities.Entity; +import finalforeach.cosmicreach.entities.EntityCreator; +import finalforeach.cosmicreach.gamestates.InGame; +import finalforeach.cosmicreach.world.Zone; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class SummonCommand implements Command { + @Override + public void register(LiteralArgumentBuilder literalArgumentBuilder) { + // TODO: make custom "identifier" argument type + literalArgumentBuilder.then( + CommandManager.argument("entityId", StringArgumentType.string()).then( + CommandManager.argument("x", RelativeFloatType.argument(() -> InGame.getLocalPlayer().getEntity().position.x)).then( + CommandManager.argument("y", RelativeFloatType.argument(() -> InGame.getLocalPlayer().getEntity().position.y)).then( + CommandManager.argument("z", RelativeFloatType.argument(() -> InGame.getLocalPlayer().getEntity().position.z)) + .executes(context -> { + String entityId = StringArgumentType.getString(context, "entityId"); + float x = RelativeFloatType.getRelativeFloat(context, "x").getValue(); + float y = RelativeFloatType.getRelativeFloat(context, "y").getValue(); + float z = RelativeFloatType.getRelativeFloat(context, "z").getValue(); + + this.handleSummon(entityId, x, y, z, context.getSource().getWorld().getZone(context.getSource().getPlayer().zoneId)); + + return 1; + }) + ) + ) + ).executes(context -> { + String entityId = StringArgumentType.getString(context, "entityId"); + float x = context.getSource().getPlayer().getEntity().position.x; + float y = context.getSource().getPlayer().getEntity().position.y; + float z = context.getSource().getPlayer().getEntity().position.z; + + this.handleSummon(entityId, x, y, z, context.getSource().getWorld().getZone(context.getSource().getPlayer().zoneId)); + + return 1; + }) + ); + } + + private void handleSummon(String entityId, float x, float y, float z, Zone zone){ + Entity entity = EntityCreator.get(entityId); + if(entity == null){ + CraterChat.Chat.sendMessage("No entity with the type " + entityId + " exists"); + return; + } + entity.setPosition(x, y, z); + zone.allEntities.add(entity); + CraterChat.Chat.sendMessage("Summoned entity of type " + entityId + " at " + x + ", " + y + ", " + z); + } + + @Override + public @NotNull String getName() { + return "summon"; + } + + @Override + public @Nullable String getDescription() { + return "Summons the specified mob"; + } + + @Override + public String getPossibleArguments() { + return " "; + } +} diff --git a/src/main/java/com/insertsoda/craterchat/impl/PluginImpl.java b/src/main/java/com/insertsoda/craterchat/impl/PluginImpl.java index 2c53317..5085391 100644 --- a/src/main/java/com/insertsoda/craterchat/impl/PluginImpl.java +++ b/src/main/java/com/insertsoda/craterchat/impl/PluginImpl.java @@ -14,7 +14,8 @@ public List> register() { HelpCommand.class, TeleportCommand.class, VersionCommand.class, - PluginsCommand.class + PluginsCommand.class, + SummonCommand.class ); } }