Posted December 23, 20168 yr I am hoping someone can assist me and I apologize in advance if my questions seem trivial. I haven't worked with Minecraft Forge modding for long. That being said, I will dive right into my question. My mod has command methods for setting a position in the world. The command works fine for setting the position to the sending entity's current position. (if I call /setpos1 my pos1 BlockPos variable is set to the entity's current X, Y, Z). The commands I have working was done as follows: 1) Create the command class and have that command class implement ICommand: public class SetPos1 implements ICommand ... 2) Register the new command during the FMLServerStartingEvent: event.RegisterServerCommand(new SetPos1(dcs)); Where dcs is an abstract class that keeps track of global variables for the mod such as the newly set position. 3) What I want to extend the command to do: I would like the player to be able to set positions other than their current position. So, two things: I want the command /setpos x y z and /setpos ~x ~y ~z. Where /setpos x y z sets the pos to the user-specified x y z coords (/setpos 256 64 512 for example) and where /setpos ~x ~y ~z sets the pos to the user-specified coords that are ~x ~y ~z units from their current position. (/setpos ~-10 ~10 ~10 would set the pos to the coords that are 10 blocks in the negative X direction, 10 blocks in the positive Y direction, and 10 blocks in the positive Z direction. Such that if the player issued the command at 0,0,0 the pos would be set to -10X, 10Y, 10Z). I am having trouble figuring out how to do this using the aliases. Can you help?
December 23, 20168 yr Author Update: I read in a similar post by diesieben07 that I should be extending CommandBase in my command classes rather than implementing ICommand. (CommandBase already implements ICommand). I see that CommandBase has a few parse functions. I will dabble in that and see what I can do.
December 27, 20168 yr Author Ok so I have the command doing exactly what I wanted it to do: 1)store the players current position. 2)alternately allow the player to store a specific position either by directly entering an integer x|~x y|~y z|~z. where the ~ symbol determines that the coordinate is to be a an integer distance from the players current pos. Thus, ~x is x blocks in the positive or negative x direction from the player's current position. Basically it works the same as /tp x y z or /tp ~x ~y ~z. I still have a couple questions that I am hoping someone has addressed already but I can't seem to find what I need in my googling. First of all, the command code: public class SetPos1 extends CommandBase { private final List aliases; private ControllerDroid controllerDroid; public SetPos1(ControllerDroid cDroid) { aliases = new ArrayList(); aliases.add("setpos1"); aliases.add("someFantasticModName setpos1"); this.controllerDroid = cDroid; } @Override public String getCommandName() { //The name of the command return "SetPositions"; } @Override public String getCommandUsage(ICommandSender sender) { //Help file summary. return "setpos1 | setpos1 x y z | setpos1 ~x ~y ~z"; } @Override public List<String> getCommandAliases() { //Return the List of aliases for this command return this.aliases; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { //Code Execution when command is run World world = sender.getEntityWorld(); int x = (int) sender.getCommandSenderEntity().posX; int y = (int) sender.getCommandSenderEntity().posY; int z = (int) sender.getCommandSenderEntity().posZ; if (world.isRemote) { //Code for client-side execution } else { //Code for server-side execution if (args.length == 3) { for (int i = 0; i < 3; i++) { if (i == 0) { if (args[i].startsWith("~")) { x = x + CommandBase.parseInt(args[i].substring(1)); } else { x = CommandBase.parseInt(args[i]); } } if (i == 1) { if (args[i].startsWith("~")) { y = y + CommandBase.parseInt(args[i].substring(1)); } else { y = CommandBase.parseInt(args[i]); } } if (i == 2) { if (args[i].startsWith("~")) { z = z + CommandBase.parseInt(args[i].substring(1)); } else { z = CommandBase.parseInt(args[i]); } } } controllerDroid.setPos1(x, y, z); } if (args.length == 0) { controllerDroid.setPos1(x, y, z); } sender.addChatMessage(new TextComponentString("Position 1 set to: [" + controllerDroid.getPos1().getX() + "=X, " + controllerDroid.getPos1().getY() + "=Y, " + controllerDroid.getPos1().getZ() + "=Z]")); } } @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { //Does the sending entity have permission to use this command? Probably return true; } @Override public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { return null; } @Override public int compareTo(ICommand o) { return 0; } } So the code works as intended when I use /setpos1 and /setpos1 x y z and so on. However I kind of want the alias to be /SomeFantasticModName setpos1: alias.add("someFantasticModName setpos1"); this doesn't seem to work though and it throws Unknown Command. So what I want is to have my mod name as a prefix to the actual commands. However the execute method isn't being called at all on an alias with multiple words in the string. It seemed to me that I could just do alias.add("someFantasticModName"); and could then handle whatever command args[0] happened to be. This seemed incorrect though since /somfantasticmodname would call all of my commands at once which seems like something I don't want to do.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.