Skip to content

Commit

Permalink
Summon command
Browse files Browse the repository at this point in the history
TODO: Make custom identifier argument type
  • Loading branch information
InsertSoda committed Jun 22, 2024
1 parent 5ec1f04 commit d962d38
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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<CommandSource> 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 "<entity id> <x> <y> <z>";
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/insertsoda/craterchat/impl/PluginImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public List<Class<? extends Command>> register() {
HelpCommand.class,
TeleportCommand.class,
VersionCommand.class,
PluginsCommand.class
PluginsCommand.class,
SummonCommand.class
);
}
}

0 comments on commit d962d38

Please sign in to comment.