Skip to content

Instantly share code, notes, and snippets.

@CatRabbit499
Created February 25, 2019 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CatRabbit499/e593b69eb2e70952ddb46e63ae47dbaa to your computer and use it in GitHub Desktop.
Save CatRabbit499/e593b69eb2e70952ddb46e63ae47dbaa to your computer and use it in GitHub Desktop.
Command Registering Example
package nathanMeyer.mods.tmpi.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.FloatArgumentType;
import nathanMeyer.mods.tmpi.constants.ChatFormatting;
import nathanMeyer.mods.tmpi.util.ChatUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandSource;
import static net.minecraft.command.Commands.argument;
import static net.minecraft.command.Commands.literal;
public class CommandGamma{
public static final CommandGamma INSTANCE = new CommandGamma();
public static void register(CommandDispatcher<CommandSource> dispatcher){
dispatcher.register(
literal("gamma").then(
argument("newGamma", FloatArgumentType.floatArg(0, 1000)).executes(
ctx -> setGamma(ctx.getSource(), FloatArgumentType.getFloat(ctx,"newGamma"))
)
).executes(ctx -> getGamma(ctx.getSource()))
);
}
private static int getGamma(CommandSource source){
ChatUtils.respond(source,ChatFormatting.PREFIX + "Gamma: " + Minecraft.getInstance().gameSettings.gammaSetting);
return 1;
}
private static int setGamma(CommandSource source, float amount){
Minecraft.getInstance().gameSettings.gammaSetting = amount;
ChatUtils.respond(source,ChatFormatting.PREFIX + ChatFormatting.valid("Gamma Updated: ") + Minecraft.getInstance().gameSettings.gammaSetting);
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment