もちろん、コマンド ハンドラが必要です。これが私のベアボーンバージョンです。役立つヒントについては、コードのコメントを確認してください。
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import akka.actor.FSM.Event;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
public class InspectCommand implements ICommand
{
private final List aliases;
public InspectCommand()
{
aliases = new ArrayList();
// These are the commands that can be used to invoke your command
aliases.add("whotookmycookies");
aliases.add("wtmc");
aliases.add("co");
}
@Override
public int compareTo(Object o)
{
return 0;
}
@Override
public String getName()
{
// The big name of your command
return "whotookmycookies";
}
@Override
public String getCommandUsage(ICommandSender var1)
{
// Help file summary
return "whotookmycookies <text>";
}
@Override
public boolean isUsernameIndex(String[] var1, int var2)
{
// Can the user use this command I think
return true;
}
@Override
public List getAliases()
{
// Return all the aliases
return this.aliases;
}
@Override
public void execute(ICommandSender sender, String[] args) throws CommandException
{
World world = sender.getEntityWorld();
// Wanna execute on the player side? Do stuff here.
if (world.isRemote)
{
}
// Execute serverside
else
{
if (args.length == 0)
{
// Send a message to the command giving entity. Remember, this can also be a command block and at this point you haven't done a type check yet.
sender.addChatMessage(new ChatComponentText("WHO TOOK MY COOKIES! Seriously though. type an argument. type /wtmc help to see available commands"));
return;
}
if (sender instanceof EntityPlayer)
{
}
}
}
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
{
// Look at native Minecraft commands like /tp to see how to return this if you wish to add tab auto completion.
return null;
}
}
次に、そのコマンドを登録する必要がありますFMLServerStartingEvent
@EventHandler
public void start(FMLServerStartingEvent event)
{
event.registerServerCommand(new InspectCommand());
}