2013-09-30 20:08:57 +00:00
|
|
|
package net.minecraftforge.client;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiChat;
|
|
|
|
import net.minecraft.command.CommandException;
|
|
|
|
import net.minecraft.command.CommandHandler;
|
|
|
|
import net.minecraft.command.ICommand;
|
|
|
|
import net.minecraft.command.ICommandSender;
|
|
|
|
import net.minecraft.command.WrongUsageException;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2013-09-30 20:08:57 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.CommandEvent;
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
2016-03-01 12:58:03 +00:00
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
|
|
|
import static net.minecraft.util.text.TextFormatting.*;
|
2013-09-30 20:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The class that handles client-side chat commands. You should register any
|
|
|
|
* commands that you want handled on the client with this command handler.
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
*
|
2013-09-30 20:08:57 +00:00
|
|
|
* If there is a command with the same name registered both on the server and
|
|
|
|
* client, the client takes precedence!
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
*
|
2013-09-30 20:08:57 +00:00
|
|
|
*/
|
|
|
|
public class ClientCommandHandler extends CommandHandler
|
|
|
|
{
|
|
|
|
public static final ClientCommandHandler instance = new ClientCommandHandler();
|
|
|
|
|
|
|
|
public String[] latestAutoComplete = null;
|
|
|
|
|
|
|
|
/**
|
2014-09-16 23:48:44 +00:00
|
|
|
* @return 1 if successfully executed, -1 if no permission or wrong usage,
|
|
|
|
* 0 if it doesn't exist or it was canceled (it's sent to the server)
|
2013-09-30 20:08:57 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int executeCommand(ICommandSender sender, String message)
|
|
|
|
{
|
|
|
|
message = message.trim();
|
|
|
|
|
|
|
|
if (message.startsWith("/"))
|
|
|
|
{
|
|
|
|
message = message.substring(1);
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:16:04 +00:00
|
|
|
String[] temp = message.split(" ");
|
|
|
|
String[] args = new String[temp.length - 1];
|
|
|
|
String commandName = temp[0];
|
|
|
|
System.arraycopy(temp, 1, args, 0, args.length);
|
2016-03-23 14:34:48 +00:00
|
|
|
ICommand icommand = getCommands().get(commandName);
|
2013-09-30 20:08:57 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (icommand == null)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-13 01:40:03 +00:00
|
|
|
if (icommand.checkPermission(this.getServer(), sender))
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
CommandEvent event = new CommandEvent(icommand, sender, args);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
if (event.exception != null)
|
|
|
|
{
|
|
|
|
throw event.exception;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-01 12:58:03 +00:00
|
|
|
this.tryExecute(sender, args, icommand, message);
|
2013-09-30 20:08:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
sender.addChatMessage(format(RED, "commands.generic.permission"));
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (WrongUsageException wue)
|
|
|
|
{
|
2014-12-02 03:11:17 +00:00
|
|
|
sender.addChatMessage(format(RED, "commands.generic.usage", format(RED, wue.getMessage(), wue.getErrorObjects())));
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
catch (CommandException ce)
|
|
|
|
{
|
2014-12-02 03:11:17 +00:00
|
|
|
sender.addChatMessage(format(RED, ce.getMessage(), ce.getErrorObjects()));
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
2014-02-05 08:05:37 +00:00
|
|
|
sender.addChatMessage(format(RED, "commands.generic.exception"));
|
2013-09-30 20:08:57 +00:00
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2014-09-16 23:48:44 +00:00
|
|
|
return -1;
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Couple of helpers because the mcp names are stupid and long...
|
2016-03-01 12:58:03 +00:00
|
|
|
private TextComponentTranslation format(TextFormatting color, String str, Object... args)
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
2016-03-01 12:58:03 +00:00
|
|
|
TextComponentTranslation ret = new TextComponentTranslation(str, args);
|
2014-02-05 08:05:37 +00:00
|
|
|
ret.getChatStyle().setColor(color);
|
2013-12-10 05:59:12 +00:00
|
|
|
return ret;
|
2013-09-30 20:08:57 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 07:34:40 +00:00
|
|
|
public void autoComplete(String leftOfCursor)
|
2013-09-30 20:08:57 +00:00
|
|
|
{
|
|
|
|
latestAutoComplete = null;
|
|
|
|
|
|
|
|
if (leftOfCursor.charAt(0) == '/')
|
|
|
|
{
|
|
|
|
leftOfCursor = leftOfCursor.substring(1);
|
|
|
|
|
|
|
|
Minecraft mc = FMLClientHandler.instance().getClient();
|
|
|
|
if (mc.currentScreen instanceof GuiChat)
|
|
|
|
{
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
List<String> commands = getTabCompletionOptions(mc.thePlayer, leftOfCursor, mc.thePlayer.getPosition());
|
2013-09-30 20:08:57 +00:00
|
|
|
if (commands != null && !commands.isEmpty())
|
|
|
|
{
|
|
|
|
if (leftOfCursor.indexOf(' ') == -1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < commands.size(); i++)
|
|
|
|
{
|
|
|
|
commands.set(i, GRAY + "/" + commands.get(i) + RESET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < commands.size(); i++)
|
|
|
|
{
|
|
|
|
commands.set(i, GRAY + commands.get(i) + RESET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
latestAutoComplete = commands.toArray(new String[commands.size()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 12:58:03 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-13 01:40:03 +00:00
|
|
|
protected MinecraftServer getServer() {
|
2016-03-01 12:58:03 +00:00
|
|
|
return Minecraft.getMinecraft().getIntegratedServer();
|
|
|
|
}
|
2016-03-08 07:34:40 +00:00
|
|
|
}
|